JDK-6384314 : REGRESSION: JComboBox that is both Editable and NonFocusable will not allow user
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 6
  • Priority: P3
  • Status: Closed
  • Resolution: Won't Fix
  • OS: generic
  • CPU: generic
  • Submitted: 2006-02-10
  • Updated: 2010-04-03
  • Resolved: 2006-03-22
Related Reports
Relates :  
Description
A DESCRIPTION OF THE REGRESSION :
When instantiating a JComboBox with setEditable(true) and setFocusable(false) there is no way for the user to enter their own values in the combo box, they are limited exclusively to the pre-supplied choices.

The JComboBox does not own the focus when being edited, but the getEditorComponent()  from ComboBoxEditor does, so the JComoboBox is the anscestor.

REPRODUCIBLE TESTCASE OR STEPS TO REPRODUCE:
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class JEditableComboBoxRegression {
    
    public static void main(String[] args) {
        JFrame f = new JFrame();
        f.setLayout(new GridLayout(0, 2));
        JComboBox cb;
        f.add(new JLabel("Plain:"));
        cb = new JComboBox(new Object[] {"Alpha", "Beta", "Gama"});
        f.add(cb);
        f.add(new JLabel("NonFocusable:"));
        cb = new JComboBox(new Object[] {"Foo", "Bar", "Baz"});
        cb.setFocusable(false);
        f.add(cb);
        f.add(new JLabel("Editable:"));
        cb = new JComboBox(new Object[] {"Left", "Right", "Center"});
        cb.setEditable(true);
        f.add(cb);
        f.add(new JLabel("Editable, then NonFocusable:"));
        cb = new JComboBox(new Object[] {"One", "Two", "Thr33"});
        cb.setEditable(true);
        cb.setFocusable(false);
        f.add(cb);
        f.add(new JLabel("NonFocusable, then Editable:"));
        cb = new JComboBox(new Object[] {"Four", "5ive", "Six"});
        cb.setFocusable(false);
        cb.setEditable(true);
        f.add(cb);
        f.pack();
        f.setVisible(true);
    }
    
}


RELEASE LAST WORKED:
5.0 Update 6

RELEASE TEST FAILS:
mustang-b70

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I was expecting, when the user clicks directly in the editable portion of the JComboBox, that the combo box goes into edit mode.

This is only from a mouse click, not using the focus traversal keys.  In both 5.0 and 6.0 you cannot tab into any of the non-focusable fields.
ACTUAL -
I could change the editable combo box, but for the bottom two ("Editable, then NonFocusable:", and "NonFocusable, then Editable:") I could not force the combobox to go into editor mode.

APPLICATION NAME: Intelliden R-Series	APPLICATION VERSION: 4.4

OBSERVED APPLICATION IMPACT:
Our application depends on such a combobox in the toolbar to allow for user selectable refresh values while that combo box is not available via Tab traversal.  Defaults are fine but you will get the occasional wacko who demans that the refresh time be set at 4.2 seconds.

Comments
EVALUATION As per ###@###.###'s evaluation, there's nothing to fix here.
22-03-2006

EVALUATION I do not think we need more documentation for JComboBox.setEditable. JComboBox is not the only component which has setEditable method and needs to be focusable in order to let user to edit using keyboard. AWT's text components and Swing's text components all have the same feature. One needs to know the implications of setFocusable(false) before calling this method. There is the Focus Specification http://download.java.net/jdk6/docs/api/java/awt/doc-files/FocusSpec.html The "focus owner" -- the Component which typically receives keyboard input. If component is not focusable it can not be "focus owner" and typically it will not receive keyboard input. Thus user can not edit using keyboard. (one can use mouse to cut and paste in this case) We might want to make "Focus Specification" more accessible for the developer so one can not miss it. For example we can provide link to it from Component.setFocusable method.
17-03-2006

EVALUATION This behavior was changed on purpose with bug 6184449. If a JComboBox (which is built of multiple children components) is unfocusable, it makes no sense for any of those children components to be focusable. Before this fix, you could click on the editor, or tab to it with the keyboard (contrary to what the submitter says). This behavior was wrong, and has been fixed. If the developer wants users to be able to edit in a JComboBox, it should be focusable.
10-02-2006