Search code examples
javaswingjcombobox

Hide JComBox Box Arrow


Is it possible to hide the arrow displayed in the JComboBox

I tried setting:

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

But it doesnt seem to work


Solution

  • You have to create a new combobox UI for that:

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

    But be careful to inherited from the base UI which matches your current look and feel.

    For example if you are using Substance you should derive your new UI from SubstanceComboBoxUI instead of BasicComboBoxUI. Otherwise you'll might loose features provided by your current L&F.

    EDIT: If you want this to get some kind of auto-completion feature it's better to stick with a normal JTextField and use AutoCompleteDecorator from SwingX.