0

I am using Substance L&F and I have set a JComboBox to editable so that i can select the value that i want from its popup, or type a new value in its Editor.

Typing a new value works fine, but if i want to delete a miss-typed letter from the Combo editor, and i click Backspace to do that it selects the letters in the editor instead of erasing them. Here is a screenshot :

enter image description here

I want the Combo editor to work like a JTextField when typing keyboard letters or Backspace or Delete in it, so is there a way to do that ? Or what is causing this?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Brad
  • 4,457
  • 10
  • 56
  • 93

2 Answers2

6

See below for the importance of an SSCCE not everything that goes wrong is a bug, most of the times it something wrong in your actual code, which without an SSCCE we are non the wiser.

Seems to work fine for me:

On start up:

enter image description here

After selecting JComboBox and pressing Backspace:

enter image description here

import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class Test {

    public Test() {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                JFrame frame = new JFrame("Test");
                frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);


                JComboBox jc = new JComboBox(new String[]{"Hello", "Bye", "World", "Cruel"});
                jc.setEditable(true);
                frame.add(jc);

                frame.pack();
                frame.setVisible(true);

            }
        });
    }

    public static void main(String[] args) {
        new Test();
    }
}

UPDATE

As per your comment:

I did not think it would work fine ! ... It is a problem in Substance; the L&F i am using.

See below for details on the Bug:

Substance: Editable JComboBox does not support backspace key

As stated:

This behavior is by design. This is a "feel" part of Substance that adds auto-completion on editable comboboxes.

Alternatively see my answer here for more L&Fs and/or a way to make your own

UPDATE 2:

Thanks to @Brad (for deciphering the bug log I linked from Substance :P) to fix this simply do:

UIManager.put( LafWidget.COMBO_BOX_NO_AUTOCOMPLETION, Boolean.TRUE ); 
Community
  • 1
  • 1
David Kroukamp
  • 36,155
  • 13
  • 81
  • 138
  • @mKorbel +1 I think so too, it looks like OP might be attempting autocomplete but without SSCCE we are sitting clueless :(. – David Kroukamp Jun 30 '13 at 14:45
  • @David .. I did not think it would work fine ! ... It is a problem in Substance; the L&F i am using. – Brad Jun 30 '13 at 14:59
  • 1
    @David .. Thanks a lot. That fixes it : UIManager.put( LafWidget.COMBO_BOX_NO_AUTOCOMPLETION, Boolean.TRUE ); – Brad Jun 30 '13 at 15:16
  • @Brad +1 glad you got it working, I saw the comment on `COMBO_BOX_NO_AUTOCOMPLETION` but wasnt sure where you would apply it so I left for you to figure. Good work :) Updated my answer with it, for completeness – David Kroukamp Jun 30 '13 at 15:27
  • I just do not understand why the Guys here are putting -1 to my question :) ... It is a right question with a problem that exists in the Substance theme and thanks to David we have found the solution to overcome it ! – Brad Jun 30 '13 at 15:39
  • @Brad +1 from me... I guess Mostly for lack of SSCCE but I think 1 or 2 might not know its also about substance L&F. Add that to your question / title as it is relevant in this question/problem. (I have done this for you of course you can edit again if needed) – David Kroukamp Jun 30 '13 at 15:42
0
UIManager.put(LafWidget.COMBO_BOX_NO_AUTOCOMPLETION, Boolean.TRUE);

This work for me!

Artificioo
  • 704
  • 1
  • 9
  • 19