Custom ComboBox Editor in JTable focus issue

From: John Wheeler (johnwheeler79_at_msn.com)
Date: 11/26/03


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?



Relevant Pages

  • Re: Edit text in box
    ... Editing them by right-clicking & choosing Edit Picture most likely produced ... That would produce the collection of editable text boxes. ... Even with Track Changes turned on the editing ... I have the option to "Protect Document" - so the ...
    (microsoft.public.word.docmanagement)
  • AfterUpdate Problems
    ... edit information. ... The text boxes use ... move to the next and try editing the remarks on the second record. ... happen when going from the first record to the second record and not others. ...
    (microsoft.public.access.formscoding)
  • Re: Im At My Wits End!!!!!!!!!!!!!!!!!!!!!!!!!
    ... connection, has no virus detector software, has little or no extras ... bitten enough times by compatibility and performance problems that I learned ... The best would indeed be a clean install, and do not judge any of those editing ...
    (rec.video.production)
  • Re: combine events to create a condition
    ... adding a record and editing a current record. ... There are some text boxes and combo boxes. ... LostFocus?) ... HTH - RuralGuy acXP WinXP Pro ...
    (microsoft.public.access.formscoding)
  • Re: Which hard drive to install video software to?
    ... in article <Which hard drive to install video software to?>, ... I have my editing software ready to go. ... So do i install the software on the external drive with the raw video, ... which is probably what the setup program for the editing ...
    (rec.video.desktop)