Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 翻转jcombobox怎么样?_Java_Jcombobox - Fatal编程技术网

Java 翻转jcombobox怎么样?

Java 翻转jcombobox怎么样?,java,jcombobox,Java,Jcombobox,如何翻转jComboBox,使弹出菜单按钮位于左侧而不是右侧 我试过: setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 但结果是: 下拉箭头的位置由与JComboBox关联的ComboBoxUI控制。通常,如果要更改此行为,必须创建自己的ComboBoxUI实现。幸运的是,对于您的特定需求,还有另一种方法。默认情况下,默认ComboBoxUI编码为将箭头放置在右侧,但如果组件方向更改为从右到左,则会将箭头放置在左侧: J

如何翻转jComboBox,使弹出菜单按钮位于左侧而不是右侧

我试过:

setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
但结果是:


下拉箭头的位置由与JComboBox关联的ComboBoxUI控制。通常,如果要更改此行为,必须创建自己的ComboBoxUI实现。幸运的是,对于您的特定需求,还有另一种方法。默认情况下,默认ComboBoxUI编码为将箭头放置在右侧,但如果组件方向更改为从右到左,则会将箭头放置在左侧:

JComboBox<String> comboBox = new JComboBox<>(new String[]{"One", "Two", "Three"});
comboBox.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);

最后,如果您的组合框是可编辑的,您可能还需要在编辑器组件上使用ApplyComponentEntation。

感谢您花时间提供帮助,但只有按钮被放置在左侧,甚至没有翻转,使组合框处于不好的状态appearance@MichaelShenouda那样的话如果你能编辑你的问题并澄清你所说的“翻转”是什么意思,这会有所帮助。你的问题目前只提到将弹出菜单按钮放在左边而不是右边。我重新编辑了我的问题,我想你现在会理解我了。@MichaelShenouda我知道,在你的操作系统上,箭头按钮是不对称的,而在我的操作系统上,箭头按钮是对称的。您可以尝试在JComboBox上使用applyComponentOrientation而不是setComponentOrientation,这可能会奏效,但我无法测试it@MichaelShenouda不客气!我认为它可能在javadocs中工作,但我不确定,因为我无法测试它。
ListCellRenderer<? super String> defaultRenderer = comboBox.getRenderer();
ListCellRenderer<String> modifiedRenderer = new ListCellRenderer<String>() {
    @Override
    public Component getListCellRendererComponent(JList<? extends String> list, String value, int index,
            boolean isSelected, boolean cellHasFocus) {
        Component component = defaultRenderer.getListCellRendererComponent(
                list, value, index, isSelected, cellHasFocus);
        component.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        return component;
    }
};
comboBox.setRenderer(modifiedRenderer);