Hide JComBox Box Arrow

Is it possible to hide the arrow displayed in JComboBox

I tried setting:

combo.getComponent(0).setSize(new Dimension(1,1)); 

But it doesn't seem to work

+6
source share
2 answers

To do this, you need to create a new combobox user interface:

 combo.setUI(new BasicComboBoxUI() { protected JButton createArrowButton() { return new JButton() { public int getWidth() { return 0; } }; } }); 

But be careful to inherit from a basic UI that matches your current look and feel.

For example, if you use a substance, you should get a new user interface from SubstanceComboBoxUI instead of BasicComboBoxUI . Otherwise, you may lose the features provided by your current L & F.

EDIT:. If you want to get some kind of autocomplete function, it's best to stick with a regular JTextField and use AutoCompleteDecorator from SwingX .

+8
source

I have been looking for some solution for this for a while, and it turns out that all that is really needed is to remember that JComboBox is an integral component.

 for (Component component : TheComboBox.getComponents()) { if (component instanceof JButton) { TheComboBox.remove(component); } } 

Thanks to mKorbel for the reminder .

+2
source

Source: https://habr.com/ru/post/897684/


All Articles