Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7144064

[macosx] "Could not find class" error in JTree's ctor when called in headless mode

XMLWordPrintable

    • b13
    • x86
    • os_x
    • Verified

        Here is a very simple test which throws error on Mac:

        import java.awt.Toolkit;
        import javax.swing.JTree;

        public final class JTreeTest {
            public static void main(final String... args) {
                System.setProperty("java.awt.headless", "true");
                System.out.println(Toolkit.getDefaultToolkit());
                final JTree tree = new JTree();
                System.out.println(tree.getPreferredSize());
            }
        }

        The error is:
        Exception in thread "main" java.lang.Error: Could not find class: sun.awt.HeadlessGraphicsEnvironment
                at java.awt.GraphicsEnvironment.createGE(GraphicsEnvironment.java:116)
                at java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:81)
                at sun.swing.SwingUtilities2.isLocalDisplay(SwingUtilities2.java:1457)
                at javax.swing.plaf.metal.MetalLookAndFeel.initComponentDefaults(MetalLookAndFeel.java:1556)
                at javax.swing.plaf.basic.BasicLookAndFeel.getDefaults(BasicLookAndFeel.java:148)
                at javax.swing.plaf.metal.MetalLookAndFeel.getDefaults(MetalLookAndFeel.java:1592)
                at javax.swing.UIManager.setLookAndFeel(UIManager.java:535)
                at javax.swing.UIManager.setLookAndFeel(UIManager.java:575)
                at javax.swing.UIManager.initializeDefaultLAF(UIManager.java:1343)
                at javax.swing.UIManager.initialize(UIManager.java:1432)
                at javax.swing.UIManager.maybeInitialize(UIManager.java:1420)
                at javax.swing.UIManager.getUI(UIManager.java:1002)
                at javax.swing.JTree.updateUI(JTree.java:714)
                at javax.swing.JTree.<init>(JTree.java:667)
                at javax.swing.JTree.<init>(JTree.java:564)
                at JTreeTest.main(JTreeTest.java:8)
        Version of jdk:
        java version "1.7.0_04-ea"
        Java(TM) SE Runtime Environment (build 1.7.0_04-ea-b227)
        Java HotSpot(TM) 64-Bit Server VM (build 23.0-b12, mixed mode)

              kizune Alexander Zuev
              son Oleg Sukhodolsky (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: