在改变某些方面时保持默认UI

时间:2016-06-10 04:26:59

标签: java swing combobox

我目前有一个总是设置在屏幕底部的JComboBox,因此内容总是会上升。看到我希望它上升,我想改变ComboBox上箭头的方向。我目前这样做:

cloud9

但是当这样做时,ComboBox变成了一个灰色的版本。我怎么能这样做它是默认的ComboBoxUI,但箭头朝上?

1 个答案:

答案 0 :(得分:2)

如果查看源代码,您会看到BasicComboBoxUI中该方法的默认实现是:

protected JButton createArrowButton() {
    JButton button = new BasicArrowButton(BasicArrowButton.SOUTH,
                                UIManager.getColor("ComboBox.buttonBackground"),
                                UIManager.getColor("ComboBox.buttonShadow"),
                                UIManager.getColor("ComboBox.buttonDarkShadow"),
                                UIManager.getColor("ComboBox.buttonHighlight"));
    button.setName("ComboBox.arrowButton");
    return button;
}

当然,覆盖BasicComboBoxUI意味着您放弃了LAF UI。例如,您将松开Windows和MAC自定义LAF。您真的需要覆盖您想要支持的所有LAF的UI。