Java Code Examples for javax.swing.plaf.synth.SynthLookAndFeel#load()

The following examples show how to use javax.swing.plaf.synth.SynthLookAndFeel#load() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
private static void createAndShowGui() {
  Class<?> clz = MainPanel.class;
  try (InputStream is = clz.getResourceAsStream("button.xml")) {
    SynthLookAndFeel synth = new SynthLookAndFeel();
    synth.load(is, clz);
    UIManager.setLookAndFeel(synth);
  } catch (IOException | ParseException | UnsupportedLookAndFeelException ex) {
    ex.printStackTrace();
    Toolkit.getDefaultToolkit().beep();
  }
  // try {
  //   SynthLookAndFeel synth = new SynthLookAndFeel();
  //   synth.load(clz.getResource("button.xml"));
  //   UIManager.setLookAndFeel(synth);
  // } catch (IOException | ParseException | UnsupportedLookAndFeelException ex) {
  //   ex.printStackTrace();
  // }
  JFrame frame = new JFrame("@title@");
  frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  frame.getContentPane().add(new MainPanel());
  frame.pack();
  frame.setLocationRelativeTo(null);
  frame.setVisible(true);
}
 
Example 2
Source File: bug8040328.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    SynthLookAndFeel lookAndFeel = new SynthLookAndFeel();
    lookAndFeel.load(new ByteArrayInputStream(synthXml.getBytes("UTF8")),
            bug8040328.class);
    UIManager.setLookAndFeel(lookAndFeel);
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            final JFrame frame = new JFrame();
            try {
                frame.setUndecorated(true);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setVisible(true);
                test(frame);
            } finally {
                frame.dispose();
            }
        }
    });
    System.out.println("ok");
}
 
Example 3
Source File: SynthTest.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    SynthLookAndFeel laf = new SynthLookAndFeel();
    InputStream in = SynthTest.class.getResourceAsStream(
            "synthconfig.xml");
    laf.load(in, SynthTest.class);

    UIManager.setLookAndFeel(laf);

    if (!Color.RED.equals(new JButton().getForeground())) {
        throw new RuntimeException("The wrong foreground color!");
    }
}
 
Example 4
Source File: SynthTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    SynthLookAndFeel laf = new SynthLookAndFeel();
    InputStream in = SynthTest.class.getResourceAsStream(
            "synthconfig.xml");
    laf.load(in, SynthTest.class);

    UIManager.setLookAndFeel(laf);

    if (!Color.RED.equals(new JButton().getForeground())) {
        throw new RuntimeException("The wrong foreground color!");
    }
}
 
Example 5
Source File: SynthTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    SynthLookAndFeel laf = new SynthLookAndFeel();
    InputStream in = SynthTest.class.getResourceAsStream(
            "synthconfig.xml");
    laf.load(in, SynthTest.class);

    UIManager.setLookAndFeel(laf);

    if (!Color.RED.equals(new JButton().getForeground())) {
        throw new RuntimeException("The wrong foreground color!");
    }
}
 
Example 6
Source File: SynthTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    SynthLookAndFeel laf = new SynthLookAndFeel();
    InputStream in = SynthTest.class.getResourceAsStream(
            "synthconfig.xml");
    laf.load(in, SynthTest.class);

    UIManager.setLookAndFeel(laf);

    if (!Color.RED.equals(new JButton().getForeground())) {
        throw new RuntimeException("The wrong foreground color!");
    }
}
 
Example 7
Source File: SwingMonitor.java    From swift-k with Apache License 2.0 5 votes vote down vote up
private void setSynthLookAndFeel() {
    SynthLookAndFeel laf = new SynthLookAndFeel();
    try {
        laf.load(this.getClass().getClassLoader().getResourceAsStream("laf.xml"), SwingMonitor.class);
        UIManager.setLookAndFeel(laf);
    }
    catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 8
Source File: SynthTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    SynthLookAndFeel laf = new SynthLookAndFeel();
    InputStream in = SynthTest.class.getResourceAsStream(
            "synthconfig.xml");
    laf.load(in, SynthTest.class);

    UIManager.setLookAndFeel(laf);

    if (!Color.RED.equals(new JButton().getForeground())) {
        throw new RuntimeException("The wrong foreground color!");
    }
}
 
Example 9
Source File: SynthTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    SynthLookAndFeel laf = new SynthLookAndFeel();
    InputStream in = SynthTest.class.getResourceAsStream(
            "synthconfig.xml");
    laf.load(in, SynthTest.class);

    UIManager.setLookAndFeel(laf);

    if (!Color.RED.equals(new JButton().getForeground())) {
        throw new RuntimeException("The wrong foreground color!");
    }
}
 
Example 10
Source File: SynthTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    SynthLookAndFeel laf = new SynthLookAndFeel();
    InputStream in = SynthTest.class.getResourceAsStream(
            "synthconfig.xml");
    laf.load(in, SynthTest.class);

    UIManager.setLookAndFeel(laf);

    if (!Color.RED.equals(new JButton().getForeground())) {
        throw new RuntimeException("The wrong foreground color!");
    }
}
 
Example 11
Source File: bug7158712.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();

    robot.setAutoDelay(500);

    SynthLookAndFeel laf = new SynthLookAndFeel();

    laf.load(new ByteArrayInputStream(SYNTH_XML.getBytes("UTF8")), bug7158712.class);

    UIManager.setLookAndFeel(laf);

    EventQueue.invokeAndWait(new Runnable() {
        public void run() {
            comboBox = new JComboBox<>(
                    new String[]{"Very Looooooooooooooooooooong Text Item 1", "Item 2"});

            JFrame frame = new JFrame();

            frame.add(comboBox, BorderLayout.NORTH);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(new Dimension(400, 300));
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    Point comboBoxLocation = Util.invokeOnEDT(new Callable<Point>() {
        @Override
        public Point call() throws Exception {
            return comboBox.getLocationOnScreen();
        }
    });

    robot.mouseMove(comboBoxLocation.x, comboBoxLocation.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            BasicComboPopup popup = (BasicComboPopup) comboBox.getAccessibleContext().getAccessibleChild(0);

            Point popupPoint = popup.getLocationOnScreen();
            Point comboBoxPoint = comboBox.getLocationOnScreen();

            if (comboBoxPoint.x - 5 != popupPoint.x ||
                    comboBoxPoint.y + comboBox.getHeight() - 5 != popupPoint.y) {
                throw new RuntimeException("Invalid popup coordinates. Popup location: " + popupPoint +
                        ", comboBox location: " + comboBoxPoint);
            }

            System.out.println("Test bug7158712 passed");
        }
    });
}
 
Example 12
Source File: bug7158712.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();

    robot.setAutoDelay(500);

    SynthLookAndFeel laf = new SynthLookAndFeel();

    laf.load(new ByteArrayInputStream(SYNTH_XML.getBytes("UTF8")), bug7158712.class);

    UIManager.setLookAndFeel(laf);

    EventQueue.invokeAndWait(new Runnable() {
        public void run() {
            comboBox = new JComboBox<>(
                    new String[]{"Very Looooooooooooooooooooong Text Item 1", "Item 2"});

            JFrame frame = new JFrame();

            frame.add(comboBox, BorderLayout.NORTH);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(new Dimension(400, 300));
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    Point comboBoxLocation = Util.invokeOnEDT(new Callable<Point>() {
        @Override
        public Point call() throws Exception {
            return comboBox.getLocationOnScreen();
        }
    });

    robot.mouseMove(comboBoxLocation.x, comboBoxLocation.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            BasicComboPopup popup = (BasicComboPopup) comboBox.getAccessibleContext().getAccessibleChild(0);

            Point popupPoint = popup.getLocationOnScreen();
            Point comboBoxPoint = comboBox.getLocationOnScreen();

            if (comboBoxPoint.x - 5 != popupPoint.x ||
                    comboBoxPoint.y + comboBox.getHeight() - 5 != popupPoint.y) {
                throw new RuntimeException("Invalid popup coordinates. Popup location: " + popupPoint +
                        ", comboBox location: " + comboBoxPoint);
            }

            System.out.println("Test bug7158712 passed");
        }
    });
}
 
Example 13
Source File: bug7158712.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();

    robot.setAutoDelay(500);

    SynthLookAndFeel laf = new SynthLookAndFeel();

    laf.load(new ByteArrayInputStream(SYNTH_XML.getBytes("UTF8")), bug7158712.class);

    UIManager.setLookAndFeel(laf);

    EventQueue.invokeAndWait(new Runnable() {
        public void run() {
            comboBox = new JComboBox<>(
                    new String[]{"Very Looooooooooooooooooooong Text Item 1", "Item 2"});

            JFrame frame = new JFrame();

            frame.add(comboBox, BorderLayout.NORTH);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(new Dimension(400, 300));
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    Point comboBoxLocation = Util.invokeOnEDT(new Callable<Point>() {
        @Override
        public Point call() throws Exception {
            return comboBox.getLocationOnScreen();
        }
    });

    robot.mouseMove(comboBoxLocation.x, comboBoxLocation.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            BasicComboPopup popup = (BasicComboPopup) comboBox.getAccessibleContext().getAccessibleChild(0);

            Point popupPoint = popup.getLocationOnScreen();
            Point comboBoxPoint = comboBox.getLocationOnScreen();

            if (comboBoxPoint.x - 5 != popupPoint.x ||
                    comboBoxPoint.y + comboBox.getHeight() - 5 != popupPoint.y) {
                throw new RuntimeException("Invalid popup coordinates. Popup location: " + popupPoint +
                        ", comboBox location: " + comboBoxPoint);
            }

            System.out.println("Test bug7158712 passed");
        }
    });
}
 
Example 14
Source File: bug7158712.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();

    robot.setAutoDelay(500);

    SynthLookAndFeel laf = new SynthLookAndFeel();

    laf.load(new ByteArrayInputStream(SYNTH_XML.getBytes("UTF8")), bug7158712.class);

    UIManager.setLookAndFeel(laf);

    EventQueue.invokeAndWait(new Runnable() {
        public void run() {
            comboBox = new JComboBox<>(
                    new String[]{"Very Looooooooooooooooooooong Text Item 1", "Item 2"});

            JFrame frame = new JFrame();

            frame.add(comboBox, BorderLayout.NORTH);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(new Dimension(400, 300));
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    Point comboBoxLocation = Util.invokeOnEDT(new Callable<Point>() {
        @Override
        public Point call() throws Exception {
            return comboBox.getLocationOnScreen();
        }
    });

    robot.mouseMove(comboBoxLocation.x, comboBoxLocation.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            BasicComboPopup popup = (BasicComboPopup) comboBox.getAccessibleContext().getAccessibleChild(0);

            Point popupPoint = popup.getLocationOnScreen();
            Point comboBoxPoint = comboBox.getLocationOnScreen();

            if (comboBoxPoint.x - 5 != popupPoint.x ||
                    comboBoxPoint.y + comboBox.getHeight() - 5 != popupPoint.y) {
                throw new RuntimeException("Invalid popup coordinates. Popup location: " + popupPoint +
                        ", comboBox location: " + comboBoxPoint);
            }

            System.out.println("Test bug7158712 passed");
        }
    });
}
 
Example 15
Source File: bug7158712.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();

    robot.setAutoDelay(500);

    SynthLookAndFeel laf = new SynthLookAndFeel();

    laf.load(new ByteArrayInputStream(SYNTH_XML.getBytes("UTF8")), bug7158712.class);

    UIManager.setLookAndFeel(laf);

    EventQueue.invokeAndWait(new Runnable() {
        public void run() {
            comboBox = new JComboBox<>(
                    new String[]{"Very Looooooooooooooooooooong Text Item 1", "Item 2"});

            JFrame frame = new JFrame();

            frame.add(comboBox, BorderLayout.NORTH);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(new Dimension(400, 300));
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    Point comboBoxLocation = Util.invokeOnEDT(new Callable<Point>() {
        @Override
        public Point call() throws Exception {
            return comboBox.getLocationOnScreen();
        }
    });

    robot.mouseMove(comboBoxLocation.x, comboBoxLocation.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            BasicComboPopup popup = (BasicComboPopup) comboBox.getAccessibleContext().getAccessibleChild(0);

            Point popupPoint = popup.getLocationOnScreen();
            Point comboBoxPoint = comboBox.getLocationOnScreen();

            if (comboBoxPoint.x - 5 != popupPoint.x ||
                    comboBoxPoint.y + comboBox.getHeight() - 5 != popupPoint.y) {
                throw new RuntimeException("Invalid popup coordinates. Popup location: " + popupPoint +
                        ", comboBox location: " + comboBoxPoint);
            }

            System.out.println("Test bug7158712 passed");
        }
    });
}
 
Example 16
Source File: bug7158712.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();

    robot.setAutoDelay(500);

    SynthLookAndFeel laf = new SynthLookAndFeel();

    laf.load(new ByteArrayInputStream(SYNTH_XML.getBytes("UTF8")), bug7158712.class);

    UIManager.setLookAndFeel(laf);

    EventQueue.invokeAndWait(new Runnable() {
        public void run() {
            comboBox = new JComboBox<>(
                    new String[]{"Very Looooooooooooooooooooong Text Item 1", "Item 2"});

            JFrame frame = new JFrame();

            frame.add(comboBox, BorderLayout.NORTH);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(new Dimension(400, 300));
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    Point comboBoxLocation = Util.invokeOnEDT(new Callable<Point>() {
        @Override
        public Point call() throws Exception {
            return comboBox.getLocationOnScreen();
        }
    });

    robot.mouseMove(comboBoxLocation.x, comboBoxLocation.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            BasicComboPopup popup = (BasicComboPopup) comboBox.getAccessibleContext().getAccessibleChild(0);

            Point popupPoint = popup.getLocationOnScreen();
            Point comboBoxPoint = comboBox.getLocationOnScreen();

            if (comboBoxPoint.x - 5 != popupPoint.x ||
                    comboBoxPoint.y + comboBox.getHeight() - 5 != popupPoint.y) {
                throw new RuntimeException("Invalid popup coordinates. Popup location: " + popupPoint +
                        ", comboBox location: " + comboBoxPoint);
            }

            System.out.println("Test bug7158712 passed");
        }
    });
}
 
Example 17
Source File: bug7158712.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();

    robot.setAutoDelay(500);

    SynthLookAndFeel laf = new SynthLookAndFeel();

    laf.load(new ByteArrayInputStream(SYNTH_XML.getBytes("UTF8")), bug7158712.class);

    UIManager.setLookAndFeel(laf);

    EventQueue.invokeAndWait(new Runnable() {
        public void run() {
            comboBox = new JComboBox<>(
                    new String[]{"Very Looooooooooooooooooooong Text Item 1", "Item 2"});

            JFrame frame = new JFrame();

            frame.add(comboBox, BorderLayout.NORTH);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(new Dimension(400, 300));
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    Point comboBoxLocation = Util.invokeOnEDT(new Callable<Point>() {
        @Override
        public Point call() throws Exception {
            return comboBox.getLocationOnScreen();
        }
    });

    robot.mouseMove(comboBoxLocation.x, comboBoxLocation.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            BasicComboPopup popup = (BasicComboPopup) comboBox.getAccessibleContext().getAccessibleChild(0);

            Point popupPoint = popup.getLocationOnScreen();
            Point comboBoxPoint = comboBox.getLocationOnScreen();

            if (comboBoxPoint.x - 5 != popupPoint.x ||
                    comboBoxPoint.y + comboBox.getHeight() - 5 != popupPoint.y) {
                throw new RuntimeException("Invalid popup coordinates. Popup location: " + popupPoint +
                        ", comboBox location: " + comboBoxPoint);
            }

            System.out.println("Test bug7158712 passed");
        }
    });
}
 
Example 18
Source File: bug7158712.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();

    robot.setAutoDelay(500);

    SynthLookAndFeel laf = new SynthLookAndFeel();

    laf.load(new ByteArrayInputStream(SYNTH_XML.getBytes("UTF8")), bug7158712.class);

    UIManager.setLookAndFeel(laf);

    EventQueue.invokeAndWait(new Runnable() {
        public void run() {
            comboBox = new JComboBox<>(
                    new String[]{"Very Looooooooooooooooooooong Text Item 1", "Item 2"});

            JFrame frame = new JFrame();

            frame.add(comboBox, BorderLayout.NORTH);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(new Dimension(400, 300));
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    Point comboBoxLocation = Util.invokeOnEDT(new Callable<Point>() {
        @Override
        public Point call() throws Exception {
            return comboBox.getLocationOnScreen();
        }
    });

    robot.mouseMove(comboBoxLocation.x, comboBoxLocation.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            BasicComboPopup popup = (BasicComboPopup) comboBox.getAccessibleContext().getAccessibleChild(0);

            Point popupPoint = popup.getLocationOnScreen();
            Point comboBoxPoint = comboBox.getLocationOnScreen();

            if (comboBoxPoint.x - 5 != popupPoint.x ||
                    comboBoxPoint.y + comboBox.getHeight() - 5 != popupPoint.y) {
                throw new RuntimeException("Invalid popup coordinates. Popup location: " + popupPoint +
                        ", comboBox location: " + comboBoxPoint);
            }

            System.out.println("Test bug7158712 passed");
        }
    });
}
 
Example 19
Source File: bug7158712.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();

    robot.setAutoDelay(500);

    SynthLookAndFeel laf = new SynthLookAndFeel();

    laf.load(new ByteArrayInputStream(SYNTH_XML.getBytes("UTF8")), bug7158712.class);

    UIManager.setLookAndFeel(laf);

    EventQueue.invokeAndWait(new Runnable() {
        public void run() {
            comboBox = new JComboBox<>(
                    new String[]{"Very Looooooooooooooooooooong Text Item 1", "Item 2"});

            JFrame frame = new JFrame();

            frame.add(comboBox, BorderLayout.NORTH);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(new Dimension(400, 300));
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    Point comboBoxLocation = Util.invokeOnEDT(new Callable<Point>() {
        @Override
        public Point call() throws Exception {
            return comboBox.getLocationOnScreen();
        }
    });

    robot.mouseMove(comboBoxLocation.x, comboBoxLocation.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            BasicComboPopup popup = (BasicComboPopup) comboBox.getAccessibleContext().getAccessibleChild(0);

            Point popupPoint = popup.getLocationOnScreen();
            Point comboBoxPoint = comboBox.getLocationOnScreen();

            if (comboBoxPoint.x - 5 != popupPoint.x ||
                    comboBoxPoint.y + comboBox.getHeight() - 5 != popupPoint.y) {
                throw new RuntimeException("Invalid popup coordinates. Popup location: " + popupPoint +
                        ", comboBox location: " + comboBoxPoint);
            }

            System.out.println("Test bug7158712 passed");
        }
    });
}
 
Example 20
Source File: bug7158712.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();

    robot.setAutoDelay(500);

    SynthLookAndFeel laf = new SynthLookAndFeel();

    laf.load(new ByteArrayInputStream(SYNTH_XML.getBytes("UTF8")), bug7158712.class);

    UIManager.setLookAndFeel(laf);

    EventQueue.invokeAndWait(new Runnable() {
        public void run() {
            comboBox = new JComboBox<>(
                    new String[]{"Very Looooooooooooooooooooong Text Item 1", "Item 2"});

            JFrame frame = new JFrame();

            frame.add(comboBox, BorderLayout.NORTH);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize(new Dimension(400, 300));
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });

    ((SunToolkit) Toolkit.getDefaultToolkit()).realSync();

    Point comboBoxLocation = Util.invokeOnEDT(new Callable<Point>() {
        @Override
        public Point call() throws Exception {
            return comboBox.getLocationOnScreen();
        }
    });

    robot.mouseMove(comboBoxLocation.x, comboBoxLocation.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);

    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            BasicComboPopup popup = (BasicComboPopup) comboBox.getAccessibleContext().getAccessibleChild(0);

            Point popupPoint = popup.getLocationOnScreen();
            Point comboBoxPoint = comboBox.getLocationOnScreen();

            if (comboBoxPoint.x - 5 != popupPoint.x ||
                    comboBoxPoint.y + comboBox.getHeight() - 5 != popupPoint.y) {
                throw new RuntimeException("Invalid popup coordinates. Popup location: " + popupPoint +
                        ", comboBox location: " + comboBoxPoint);
            }

            System.out.println("Test bug7158712 passed");
        }
    });
}