0

I have a custom JComboBox that I have populated with JCheckBoxes, and the combo box is used as an editor within a table.

JComboCheckBox

I am trying to make it so that when the user selects an item, the popup menu is not dismissed. The only time it should be dismissed is when it looses focus.

I have attempted this by overriding the setPopupVisible method, but it is not working.

@Override
public void setPopupVisible(boolean v) {
    if (v && !this.isPopupVisible()) {
        super.setPopupVisible(true);
    } else if (requiresDismissal) {
        requiresDismissal = false;
        super.setPopupVisible(false);
    } else {
        requiresDismissal = false;
    }
}

requiresDismissal is a boolean value set to true whenever one of the objects within the popup menu is clicked. I tested further by attempting to disable the ability to dismiss the popupmenu entirely, but nothing I try seems to work.

Thank you in advance for the help!

Duffluc
  • 27
  • 2
  • 6
  • Did you check this out [link](http://stackoverflow.com/a/2860376/702048) – Pendula Jan 13 '16 at 21:49
  • Edited - submitted prematurely by accident. – Duffluc Jan 13 '16 at 21:50
  • A `JComboBox` is supposed to close its popup after selection. Otherwise, why not use a `JList` or just a group of buttons? – user1803551 Jan 13 '16 at 21:51
  • A JList might work, true, but for the sake of argument let's say I need to use a JComboBox - is there a way to override its default functionality to stop it from closing? – Duffluc Jan 13 '16 at 21:59
  • 1
    @Duffluc That's counter intuitive, a `JComboBox` is only suppose to have a single selected item – MadProgrammer Jan 13 '16 at 22:02
  • 1
    From [the tutorials](https://docs.oracle.com/javase/tutorial/uiswing/components/combobox.html#listeners): "*Only one item at a time can be selected in a combo box*". – user1803551 Jan 13 '16 at 22:03
  • 1
    I would consider devising your own component which can meet the requirements you are trying to achieve, you will have a lot less issues and have to generate a lot less of hacks to make it work – MadProgrammer Jan 13 '16 at 22:15
  • Alright, thank you, I will try to refactor with another component. – Duffluc Jan 14 '16 at 21:00

0 Answers0