本文介绍了隐藏JComBox框箭头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以隐藏JComboBox中显示的箭头

Is it possible to hide the arrow displayed in the JComboBox

我尝试设置:

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

但是它似乎不起作用

推荐答案

您必须为此创建一个新的组合框UI:

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;
            }
        };
    }
});

但是要小心从与当前外观匹配的基本UI继承.

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

例如,如果您正在使用Substance,则应从SubstanceComboBoxUI而不是BasicComboBoxUI派生新的UI.否则,您可能会失去当前L& F提供的功能.

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.

编辑:如果您希望它具有某种自动完成功能,最好坚持使用普通的JTextField并使用AutoCompleteDecorator swingx.java.net/"rel =" noreferrer> SwingX .

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.

这篇关于隐藏JComBox框箭头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 12:27