扩展具有包级别访问权限的类

时间:2013-10-24 11:51:11

标签: java swing look-and-feel nimbus uimanager

Java 1.6具有包含级别访问权限的Synth plaf类。

我尝试扩展这些

package javax.swing.plaf.synth;

import javax.swing.JComponent;
import javax.swing.plaf.ComponentUI;

class MyCheckBoxUI extends SynthCheckBoxUI {
    public static ComponentUI createUI(JComponent b) {
        return new MyCheckBoxUI();
    }
}

import javax.swing.JComponent; import javax.swing.plaf.ComponentUI; class MyCheckBoxUI extends SynthCheckBoxUI { public static ComponentUI createUI(JComponent b) { return new MyCheckBoxUI(); } }

然而,在实例化时,

失败了

线程“main”中的异常java.lang.IllegalAccessError:类javax.swing.plaf.synth.MyCheckBoxUI无法访问其超类javax.swing.plaf.synth.SynthCheckBoxUI

public class TestApp {
    public static void main(String[] args) throws Throwable {
        for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                UIManager.setLookAndFeel(info.getClassName());

                break;
            }
        }

        UIManager.put("CheckBoxUI", "javax.swing.plaf.synth.MyCheckBoxUI");

        JFrame frame = new JFrame();

        frame.add(new JCheckBox("Hello", true));
        frame.pack();
        frame.setVisible(true);
    }
}

有人可以建议我如何解决这种情况。我必须坚持使用jdk 1.6

0 个答案:

没有答案