Remove the down arrow in JComboBox

I want to create an automatic complete program, and for this I use JComboBox .

Now I want to remove the down arrow in JComboBox . How to remove the arrow?

+1
source share
1 answer

JComboBox is a composite JComponent and contains JButton with Icon , you can remove it with setIcon (null) or replace it with another icon

for example (how to do this with simple steps, NOTICE is only valid for Metal Look and Feel )

  JComboBox coloredArrowsCombo = myComboBox; BufferedImage coloredArrowsImage = null; try { coloredArrowsImage = ImageIO.read(AppVariables.class.getResource("resources/passed.png")); } catch (IOException ex) { Logger.getLogger(someClessName.class.getName()).log(Level.SEVERE, null, ex); } if (!(coloredArrowsImage == null)) { Icon coloredArrowsIcon = new ImageIcon(coloredArrowsImage); Component[] comp = coloredArrowsCombo.getComponents(); for (int i = 0; i < comp.length; i++) { if (comp[i] instanceof MetalComboBoxButton) { MetalComboBoxButton coloredArrowsButton = (MetalComboBoxButton) comp[i]; coloredArrowsButton.setComboIcon(coloredArrowsIcon); break; } } } 

EDIT: for better output, you can place coloredArrowsButton.setRolloverIcon(someIcon);

+2
source

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


All Articles