为所有JComboBox设置ComboBoxUI

时间:2013-12-23 21:06:53

标签: java swing jcombobox uimanager

您好我想在我的应用中更改所有ComboBox的外观。

MyComboBox类:

class MyComboBoxUI extends BasicComboBoxUI {


    public static ComponentUI createUI(JComponent c) {
        return new MyComboBoxUI();
    }

    protected JButton createArrowButton() {
        JButton button = new BasicArrowButton(BasicArrowButton.EAST);
        return button;
    }
}

我称之为:

UIManager.put("ComboBoxUI", "MyComboBoxUI");

它产生了这个错误:

UIDefaults.getUI() failed: no ComponentUI class for: javax.swing.JComboBox

当我使用时:

someComboBox.setUI((ComboBoxUI) MyComboBoxUI.createUI(someComboBox));

它就像一个魅力

0 个答案:

没有答案