Search code examples
javanetbeansjcombobox

How do you edit a JComboBox dropdown arrow?


How do you remove the background of a JComboBox dropdown arrow, leaving only the small triangle? The dropdown list was created using the JComboBox tool in Netbeans version 8.


Solution

  • @Drew I don't think the OP wants the button to disappear - he just wants the button to have no visible manifestation other than the arrow triangle:

    JComboBox<String> box = new JComboBox<>();
    final Color bg = box.getBackground();
    box.setUI(new BasicComboBoxUI() {
        @Override
        protected JButton createArrowButton() {
            JButton b = super.createArrowButton();
            b.setBackground(bg);
            b.setBorderPainted(false);
            return b; 
       }
    });