开发者

Remove the down arrow in JComboBox

I want to create an auto complete program and I am using JComboBox for this.

Now I want to remove the down arrow in the JComboBox. How to rem开发者_如何学Pythonove the arrow?


JComboBox is compound JComponent and contains JButton with Icon, you can remove that by setIcon(null) or replace with another Icon

for example (how to do it with simple steps, NOTICE valid just 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 put here coloredArrowsButton.setRolloverIcon(someIcon);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜