swingx
  1. swingx
  2. SWINGX-1532

Improve usability for the autocomplete combobox

    Details

    • Type: Improvement Improvement
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Autocomplete
    • Labels:
      None

      Description

      Also see http://stackoverflow.com/q/13138266/1076463

      The use-case is having an editable auto-complete combobox where you want to trigger a long-running task when the user has finished changing the selection. You do not want to trigger the long-running task when

      • the user is still typing
      • the user is navigating with the keyboard arrows
      • the user is navigating with the mouse

      You do want to trigger the long-running task when

      • the user selects an item with the mouse
      • the user types an item and confirms with ENTER
      • the user selects an item using keyboard arrow navigation and confirms with ENTER

      I did not manage to fulfill all these requirements. Attached to this issue 3 classes which show 3 approaches, but none of them work completely. The ImprovedApproach comes closest, but still requires an ENTER after mouse selection.

      The last issue usability issue is editing of an existing item to a slightly different one. This is present in all 3 of the samples attached to this issue. You override way too easily the auto-completed part, e.g. in the ImprovedApproach sample do

      The actual example which was reported by one of our users was the editing of //SERVER1/Data/... to /server/data/..., so having an option to switch off case-insensitive auto-completion is not enough.

        Activity

        Hide
        bobndrew added a comment - - edited

        Running the OnlyConnectButton.java and the NaiveApproach.java example showed the same behaviour... because the same class was instantiated

        OnlyConnectButton.java
        ...
          @Override
          public void run() {
            new NaiveApproach().show( "Button only" );
          }
        ...
        

        I fixed that and added a new class WorksAsDesired.java to the samples20121031.zip file which works as you described in your use-case. I used an ActionListener on Button1 clicks (like kleopatra suggested on stackoverflow).

        WorksAsDesired.java
        ...
          @Override
          public void actionPerformed(ActionEvent e)
          {
            if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0)
        ...
        

        A new problem is that the CombobBox in your example is editable; because of that 3 action events are fired (mentioned here in the forum) after mouse-clicking. One empty and two events with the new selection. If the ComboBox is not editable only one event is fired.
        I debugged and read through the org.jdesktop.swingx.autocomplete.AutoCompleteDocument.java code. Maybe the selecting flag should be true when entering the remove(int offs, int len) method?

        I have no ideas regarding your "usability issue", sorry.

        (tested on Windows 7 64bit, Java 1.7.0_07-b10)

        Show
        bobndrew added a comment - - edited Running the OnlyConnectButton.java and the NaiveApproach.java example showed the same behaviour... because the same class was instantiated OnlyConnectButton.java ... @Override public void run() { new NaiveApproach().show( "Button only" ); } ... I fixed that and added a new class WorksAsDesired.java to the samples20121031.zip file which works as you described in your use-case. I used an ActionListener on Button1 clicks (like kleopatra suggested on stackoverflow). WorksAsDesired.java ... @Override public void actionPerformed(ActionEvent e) { if ((e.getModifiers() & InputEvent.BUTTON1_MASK) != 0) ... A new problem is that the CombobBox in your example is editable ; because of that 3 action events are fired (mentioned here in the forum ) after mouse-clicking. One empty and two events with the new selection. If the ComboBox is not editable only one event is fired. I debugged and read through the org.jdesktop.swingx.autocomplete.AutoCompleteDocument.java code. Maybe the selecting flag should be true when entering the remove(int offs, int len) method? I have no ideas regarding your "usability issue", sorry. (tested on Windows 7 64bit, Java 1.7.0_07-b10)
        Hide
        bobndrew added a comment -

        fixed and new example

        Show
        bobndrew added a comment - fixed and new example
        Hide
        Karl Schaefer added a comment -

        The forum example (for three events) is invalid because the combo box is being used as a cell editor. The correct listener to use is a CellEditorListener on the ComboBoxCellEditor and not an ActionListener on the decorated JComboBox.

        Furthermore, I don't understand the point of this bug. If you want to ensure that the user is done selecting, you need to give the user a way to specify that, such as a button.

        Show
        Karl Schaefer added a comment - The forum example (for three events) is invalid because the combo box is being used as a cell editor. The correct listener to use is a CellEditorListener on the ComboBoxCellEditor and not an ActionListener on the decorated JComboBox. Furthermore, I don't understand the point of this bug. If you want to ensure that the user is done selecting, you need to give the user a way to specify that, such as a button.
        Hide
        robin_stevens added a comment -

        @Karl Schaefer

        I have a button, but it is very counter-intuitive that you have to click it after selecting an item from a combobox. Therefore I tried having all the possibilities: use the button, type + hit ENTER, mouse selection, keyboard navigation. But that is probably more a problem with a JCombobox then with the auto-completion.

        However, there is still the 'editing an existing entry' usability issue as described above. I just logged this issue with the illustration on how I am using the auto-completed combo box, including all weird constructions trying to only trigger the connection when the user has finished editing. Might have been that I was using the component completely wrong ...

        Show
        robin_stevens added a comment - @Karl Schaefer I have a button, but it is very counter-intuitive that you have to click it after selecting an item from a combobox. Therefore I tried having all the possibilities: use the button, type + hit ENTER, mouse selection, keyboard navigation. But that is probably more a problem with a JCombobox then with the auto-completion. However, there is still the 'editing an existing entry' usability issue as described above. I just logged this issue with the illustration on how I am using the auto-completed combo box, including all weird constructions trying to only trigger the connection when the user has finished editing. Might have been that I was using the component completely wrong ...
        Hide
        bobndrew added a comment -

        @Karl Schaefer

        The point of this bug is the attempt to make an auto-complete-ComboBox behave like the adress-/search-ComboBox-Field in recent internet browsers.

        If you type a URL or a search term in Firefox you get matching adresses in a popup. If you hit enter or click an item the website is loaded. In Firefox there's is an (optional) tiny arrow button, like you mentioned, to give the user the possibility to start the webpage loading. But it's only visible if you typed something new; it's replaced with the "add to favorites" button, after the pages is loaded.

        In Opera and Safari there is no "Go to URL now!"-button anymore: just enter-keying and mouse-clicking.

        Show
        bobndrew added a comment - @Karl Schaefer The point of this bug is the attempt to make an auto-complete-ComboBox behave like the adress-/search-ComboBox-Field in recent internet browsers. If you type a URL or a search term in Firefox you get matching adresses in a popup. If you hit enter or click an item the website is loaded. In Firefox there's is an (optional) tiny arrow button, like you mentioned, to give the user the possibility to start the webpage loading. But it's only visible if you typed something new; it's replaced with the "add to favorites" button, after the pages is loaded. In Opera and Safari there is no "Go to URL now!"-button anymore: just enter-keying and mouse-clicking.
        Hide
        kleopatra added a comment - - edited

        Actually, we already support the WorksAsDesired - in the ComboBoxCellEditor The implemenation is different from the one I suggested on SO but to a similar effect.

        • install a ComboBoxCellEditor around the decorated comboBox
        • for commit-semantic notification, add a CellEditorListener to the editor
            final JComboBox withEditor = new JComboBox( new String[]{
                    "http://www.google.com",
                    "http://java.net/jira/browse/SWINGX",
                    "http://today.java.net/pub/a/today/2007/07"
                      +"/19/adding-auto-completion-to-swing-comboboxes.html",
                    "http://docs.oracle.com/javase/7/docs/api/",
                    "http://java.net/jira/browse/SWINGX-940",
                    "http://java.net/jira/browse/SWINGX-1264"
                } );
            withEditor.setEditable( true );
            AutoCompleteDecorator.decorate( withEditor );
            ComboBoxCellEditor editor = new ComboBoxCellEditor(withEditor);
            CellEditorListener listener = new CellEditorListener() {
                
                @Override
                public void editingStopped(ChangeEvent e) {
                    connectToItem((String) withEditor.getSelectedItem(), outputArea);
                }
                
                @Override
                public void editingCanceled(ChangeEvent e) {
                }
            };
            editor.addCellEditorListener(listener);
            contentPane.add(withEditor, BorderLayout.SOUTH);
        
        
        Show
        kleopatra added a comment - - edited Actually, we already support the WorksAsDesired - in the ComboBoxCellEditor The implemenation is different from the one I suggested on SO but to a similar effect. install a ComboBoxCellEditor around the decorated comboBox for commit-semantic notification, add a CellEditorListener to the editor final JComboBox withEditor = new JComboBox( new String []{ "http: //www.google.com" , "http: //java.net/jira/browse/SWINGX" , "http: //today.java.net/pub/a/today/2007/07" + "/19/adding-auto-completion-to-swing-comboboxes.html" , "http: //docs.oracle.com/javase/7/docs/api/" , "http: //java.net/jira/browse/SWINGX-940" , "http: //java.net/jira/browse/SWINGX-1264" } ); withEditor.setEditable( true ); AutoCompleteDecorator.decorate( withEditor ); ComboBoxCellEditor editor = new ComboBoxCellEditor(withEditor); CellEditorListener listener = new CellEditorListener() { @Override public void editingStopped(ChangeEvent e) { connectToItem(( String ) withEditor.getSelectedItem(), outputArea); } @Override public void editingCanceled(ChangeEvent e) { } }; editor.addCellEditorListener(listener); contentPane.add(withEditor, BorderLayout.SOUTH);

          People

          • Assignee:
            Karl Schaefer
            Reporter:
            robin_stevens
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: