Custom ComboBox Editor in JTable focus issue
From: John Wheeler (johnwheeler79_at_msn.com)
Date: 11/26/03
- Next message: Taras_96: "JScrollPane not appearing"
- Previous message: Kleopatra: "Re: MouseListener doesn't react in JLabel"
- Next in thread: Kleopatra: "Re: Custom ComboBox Editor in JTable focus issue"
- Reply: Kleopatra: "Re: Custom ComboBox Editor in JTable focus issue"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 25 Nov 2003 16:56:55 -0800
I created a custom JComboBox.KeySelectionManager that allows
progressive key selection. For instance, when installed in a combo box
populated with U.S. states, a user can type 'ar' and the combo box
will select 'Arizona' instead of 'Rhode Island.'
I install combo boxes with these KeySelectionManagers as JTable
CellEditors. When the JTable passes focus to the component, I type one
key, editing is stopped, and focus returns to the table (BTW, I have
setSurrendersFocusOnKeystroke(true)). Consequently, the
KeySelectionManager's behavior is not realized. In order to intercept
calls to editingStopped, I created a subclass of JTable with an
overridden editingStopped method that installs KeyAdapter's on the
combo boxes and when 'tab' is pressed, i call super.editingStopped
(code below). Now the combo boxes retain focus, but mouse events do
not stop editing like they used to. So, if I begin editing in a combo
box and click another cell, the editing session doesn't stop.
public void editingStopped(final ChangeEvent ce) {
final DefaultCellEditor dce = (DefaultCellEditor)
ce.getSource();
if (!(dce.getComponent() instanceof JComboBox)) {
super.editingStopped(ce);
return;
}
dce.getComponent().addKeyListener(new KeyAdapter() {
public void keyTyped(KeyEvent ke) {
if (ke.getKeyChar() == KeyEvent.VK_TAB)
TxTable.super.editingStopped(ce);
}
});
}
Can anyone help?
- Next message: Taras_96: "JScrollPane not appearing"
- Previous message: Kleopatra: "Re: MouseListener doesn't react in JLabel"
- Next in thread: Kleopatra: "Re: Custom ComboBox Editor in JTable focus issue"
- Reply: Kleopatra: "Re: Custom ComboBox Editor in JTable focus issue"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|