I am trying to add JPopupMenu
(on right click) to an array of check boxes and am doing it in below way:
JPanel Pane = new JPanel();
Pane.setLayout(new BoxLayout(Pane, BoxLayout.PAGE_AXIS));
m_popMenu = new JPopupMenu();
JMenuItem item = new JMenuItem("Setup");
item.addActionListener(this);
m_popMenu.add(item);
for (int k = 0; k < 5; k++) {
checkBoxes[k] = new JCheckBox(List[k]); //in List i have names for CheckBoxes
checkBoxes[k].addActionListener(this);
//For popupmenu item
checkBoxes[k].addMouseListener(this);
Pane.add(checkBoxes[k]);
checkBoxes[k].add(m_popMenu);
}
This code does what I need exactly but GUI has some problems. If only two check boxes are there, check boxes gets aligned with more space and if I right click to open popup menu the alignment changes properly.
Whenever I open popup by right click (for the first time) the checkboxes reduce space between them.
Why does this happen?