jcombobox as cell editor java.awt.IllegalComponentStateException: component must be showing on the screen to determine its location

后端 未结 4 1391
天命终不由人
天命终不由人 2021-01-19 10:20

I am using a custom JComboBox as a cell editor in a JTable. When the users gets to the cell using keyboard controls it tries to open the popup. This causes the following e

4条回答
  •  我在风中等你
    2021-01-19 11:08

    First, let me explain what comboBox.putClientProperty("JComboBox.isTableCellEditor", Boolean.TRUE); does. Normally, hoovering the mouse over an item or pressing the arrow keys on the keyboard will cause the selection of items on the JComboBox immediately. Since selection events from the JComboBox will cause the cell edit process to stop, this behavior is not suitable for table cells. So when setting this special client property items will be shown selected inside the popup list but not set on the JComboBox yet. Only committed items (via click or Enter key) will change the selected item on the JComboBox causing the end of the edit then. At least, this holds for BasicLookAndFeel and its derivatives.

    The problem you have is completely different. As the exception message and the stack trace clearly say, the look and feel tries to open the JPopupMenu associated with the JComboBox (as you requested) but it can’t determine the on-screen location for the popup menu because your JComboBox is not shot showing on the screen. The reason why it wants the location of the JComboBox is that it opens the new window relative to the JComboBox.

    The remaining question is why you received a focusGained from a JComboBox that is not showing on the screen (or why you thought you did).

提交回复
热议问题