I'm working with GridBagLayout
and I can't figure why the JCheckBox
don't align. I've tried to set alignement as a JCheckBox
parameter(i.e checkBox.setAlignementX(LEFT_ALIGNEMENT)
). It did'nt worked.
I first tried using BorderLayout
, but it turned out even worst
What I'm trying to acheive is this
I want the threee main categories(Physique, Psychologique and Social) to be set on the complete left, and i want the sub-categories to be set just a bit offset. That way you'll know it's a sub-categorie(according to the lines i've drawn).
There uis three JPanel
, one for each category.
This is not the original code but it somewhat reproduce the problem i have.
public class Window extends JFrame {
private JButton button = new JButton("Generer");
private JCheckBox physique = new JCheckBox("Traits Physiques");
private JCheckBox psychologic = new JCheckBox("Traits Psychologiques");
private JCheckBox mass = new JCheckBox("Masse");
private JCheckBox quality = new JCheckBox("Qualité");
private JTextArea text = new JTextArea("");
private JScrollPane scroller = new JScrollPane(text);
private JPanel panel = new JPanel();
public Window() {
setLayout(new BorderLayout());
setTitle("Personnage");
setSize(500, 350);
setResizable(false);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLocationRelativeTo(null);
text.setEditable(false);
arrange();
getContentPane().add(panel, BorderLayout.WEST);
getContentPane().add(scroller, BorderLayout.CENTER);
getContentPane().add(button, BorderLayout.SOUTH);
setVisible(true);
}
/**
* Arrange all the layout
*/
private void arrange() {
JPanel phPanel = new JPanel();
JPanel psPanel = new JPanel();
GridBagConstraints gbcPanel, gbcPh, gbcPs;
gbcPanel = gbcPh = gbcPs = new GridBagConstraints();
panel.setLayout(new GridBagLayout());
gbcPanel.gridx = 0;
gbcPanel.gridy = 0;
gbcPanel.gridheight = 1;
gbcPanel.gridwidth = 1;
panel.add(phPanel, gbcPanel);
gbcPanel.gridy = 1;
panel.add(psPanel, gbcPanel);
//---------------------------
gbcPh.gridx = 0;
gbcPh.gridy = 0;
gbcPh.gridheight = 1;
gbcPh.gridwidth = 2;
phPanel.add(physique, gbcPh);
gbcPh.gridx = 1;
gbcPh.gridy = 1;
gbcPh.gridwidth = 1;
phPanel.add(mass, gbcPh);
//--------------------------
gbcPs.gridx = 0;
gbcPs.gridy = 0;
gbcPs.gridheight = 1;
gbcPs.gridwidth = 2;
psPanel.add(psychologic, gbcPs);
gbcPs.gridx = 1;
gbcPs.gridy = 1;
gbcPs.gridwidth = 1;
psPanel.add(quality, gbcPs);
//------------------------
}
}
I want the main category(i.e physique and psychologic) to be align totally left and the sub category(i.e mass and quality) to be a bit offset. I can't do that, i don't know how, i've read multiple tutorial etc...