Java Swing:自定义ComponentUI实现

时间:2015-01-22 22:17:35

标签: java swing look-and-feel

我正在研究Java swing的外观,我的问题是为没有UIClassID的组件创建一个ComponentUI。

例如,javax.swing.Box组件没有特定的类id,但它确实扩展了JComponent,它返回" ComponentUI"作为其类id(JComponent#getUIClassID)。

我已尝试在UIDefaults中设置UI,但我的自定义ComponentUI实现中的createUI方法未被调用。

defaults.put("ComponentUI", FancyComponentUI.class.getName());

这是FancyComponentUI类

public class FancyComponentUI extends ComponentUI {

    public static ComponentUI createUI(JComponent c) {
        System.out.println("Something is happening!");
        return new FancyComponentUI();
    }

}

我所做的所有其他自定义用户界面工作都非常好,它只是ComponentUI实现的问题。

0 个答案:

没有答案