Java Code Examples for javax.swing.SwingUtilities#invokeAndWait()

The following examples show how to use javax.swing.SwingUtilities#invokeAndWait() . 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: BigDataViewerTransformationWindow.java    From SPIM_Registration with GNU General Public License v2.0 6 votes vote down vote up
public static void disposeViewerWindow( final BigDataViewer bdv )
{
	try
	{
		SwingUtilities.invokeAndWait( new Runnable()
		{
			@Override
			public void run()
			{
				final ViewerFrame frame = bdv.getViewerFrame();
				final WindowEvent windowClosing = new WindowEvent( frame, WindowEvent.WINDOW_CLOSING );
				frame.dispatchEvent( windowClosing );
			}
		} );
	}
	catch ( final Exception e )
	{}
}
 
Example 2
Source File: DashStrokeTest.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
        try {
        SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            drawGui();
        }

        });
        } catch (Exception e) {
        }

        if (printed) {
            checkBI(bi, Color.RED);
        }
}
 
Example 3
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
public void executeAsyncScriptWithNullReturn() throws Throwable {
    try {
        driver = new JavaDriver();
        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }
        });
        WebElement element1 = driver.findElement(By.name("text-field"));
        WebElement element2 = (WebElement) ((JavascriptExecutor) driver).executeAsyncScript("$2.call(null);", element1);
        AssertJUnit.assertNull(element2);
    } finally {
        JavaElementFactory.reset();
    }
}
 
Example 4
Source File: MissingCharsKorean.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(() -> {
        setupUI();
    });

    testStartLatch.await();

    if (startTest) {
        glyphTest();

        frame.dispose();

        if (testPassed) {
            System.out.println(testResult);
        } else {
            throw new RuntimeException("Korean text missing characters : "
                    + testResult);
        }
    } else {
        throw new RuntimeException("User has not executed the test");
    }
}
 
Example 5
Source File: PageDialogMarginValidation.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 {
    SwingUtilities.invokeAndWait(() -> {
        doTest(PageDialogMarginValidation::pageMarginTest);
    });
    mainThread = Thread.currentThread();
    try {
        Thread.sleep(30000);
    } catch (InterruptedException e) {
        if (!testPassed && testGeneratedInterrupt) {
            throw new RuntimeException(""
                    + "Margin validation is not correct");
        }
    }
    if (!testGeneratedInterrupt) {
        throw new RuntimeException("user has not executed the test");
    }
}
 
Example 6
Source File: JInternalFrameTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@AfterMethod
public void disposeDriver() throws Throwable {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setVisible(false);
            frame.dispose();
        }
    });
    if (driver != null) {
        driver.quit();
    }
}
 
Example 7
Source File: NativeEventsTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void enteredGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_ENTERED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.keyPress(KeyEvent.VK_ALT);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    r.keyRelease(KeyEvent.VK_ALT);
    new EventQueueWait() {
        @Override
        public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    new Actions(driver).moveToElement(t).keyDown(Keys.ALT).moveToElement(b).click().keyUp(Keys.ALT).perform();
    AssertJUnit.assertEquals(expected, t.getText());

}
 
Example 8
Source File: RendererDisplayerTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void clickOn(final RendererPropertyDisplayer ren) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            Point toClick = new Point(5,5);
            Component target=ren.getComponentAt(toClick);
            MouseEvent me = new MouseEvent(target, MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), MouseEvent.BUTTON1_MASK, toClick.x, toClick.y, 2, false);
            target.dispatchEvent(me);
        }
    });
    sleep();
}
 
Example 9
Source File: JTableTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@BeforeMethod
public void showDialog() throws Throwable {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame(JTableTest.class.getSimpleName());
            frame.setName("frame-" + JTableTest.class.getSimpleName());
            frame.getContentPane().add(new TableFilterDemo(), BorderLayout.CENTER);
            frame.pack();
            frame.setAlwaysOnTop(true);
            frame.setVisible(true);
        }
    });
}
 
Example 10
Source File: SplashScreen.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void init()
{
	try
	{
		SwingUtilities.invokeAndWait(() ->
		{
			if (INSTANCE != null)
			{
				return;
			}

			try
			{
				boolean hasLAF = UIManager.getLookAndFeel() instanceof SubstanceRuneLiteLookAndFeel;
				if (!hasLAF)
				{
					UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
				}
				INSTANCE = new SplashScreen();
				if (hasLAF)
				{
					INSTANCE.getRootPane().putClientProperty(SubstanceSynapse.COLORIZATION_FACTOR, 1.0);
				}
			}
			catch (Exception e)
			{
				log.warn("Unable to start splash screen", e);
			}
		});
	}
	catch (InterruptedException | InvocationTargetException bs)
	{
		throw new RuntimeException(bs);
	}
}
 
Example 11
Source File: FocusAfterBadEditTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void releaseKey(final Component target, final int key) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            KeyEvent ke = new KeyEvent(target, KeyEvent.KEY_RELEASED, System.currentTimeMillis(), 0, key, (char) key);
            target.dispatchEvent(ke);
        }
    });
    sleep();
}
 
Example 12
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void getAccessibleName() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });
    WebElement element1 = driver.findElement(By.name("text-field"));
    AssertJUnit.assertEquals("Text Field", element1.getAttribute("accessibleName"));
}
 
Example 13
Source File: JavaDriverTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public void getCText() throws Throwable {
    driver = new JavaDriver();
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        }
    });

    WebElement element1 = driver.findElement(By.cssSelector("button"));
    AssertJUnit.assertEquals("Click Me!!", element1.getAttribute("cText"));
    WebElement element2 = driver.findElement(By.cssSelector("menu"));
    AssertJUnit.assertEquals("File", element2.getAttribute("cText"));
}
 
Example 14
Source File: RColorChooserTest.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@AfterMethod
public void disposeDriver() throws Throwable {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setVisible(false);
            frame.dispose();
        }
    });
}
 
Example 15
Source File: bug8034955.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {

        @Override
        public void run() {
            JFrame frame = new JFrame();
            frame.getContentPane().add(new JLabel("<html>a<title>"));
            frame.pack();
            frame.setVisible(true);
        }
    });
}
 
Example 16
Source File: PluginManagerActionTest.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void testMemLeakPluginManagerUI () throws Exception {
    help = this;
    
    close = new JButton ();
    SwingUtilities.invokeAndWait (new Runnable () {
        public void run () {
            ui = new PluginManagerUI (close);
        }
    });
    
    assertNotNull (ui);
    ref = new WeakReference<PluginManagerUI> (ui);
    assertNotNull (ref.get ());
    
    dlg = new JDialog (new JFrame ());
    dlg.setBounds (100, 100, 800, 500);
    dlg.add (ui);

    SwingUtilities.invokeAndWait (new Runnable () {
        public void run () {
            dlg.setVisible (true);
        }
    });
    ui.initTask.waitFinished ();
    Thread.sleep (1000);
    SwingUtilities.invokeAndWait (new Runnable () {
        public void run () {
            dlg.setVisible (false);
            dlg.getContentPane ().removeAll ();
            dlg.dispose ();
        }
    });
    Thread.sleep (10500);
    //dlg = null;
    close = null;

    ui = null;
    assertNull (ui);
    
    ToolTipManager.sharedInstance ().mousePressed (null);
    // sun.management.ManagementFactoryHelper.getDiagnosticMXBean().dumpHeap("/tmp/heapdump2.out", true);
    assertGC ("Reference to PluginManagerUI is empty.", ref);

    assertNotNull (ref);
    assertNull (ref.get ());
}
 
Example 17
Source File: Test7024235.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private void test() throws Exception {
    SwingUtilities.invokeAndWait(this);
    if (!this.passed && AUTO) { // error reporting only for automatic testing
        throw new Error("TEST FAILED");
    }
}
 
Example 18
Source File: bug8057791.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
public static void main(String[] args) {
    try {
        UIManager.setLookAndFeel(new NimbusLookAndFeel());

        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                final int listWidth = 50;
                final int listHeight = 50;
                final int selCellIndex = 0;

                JList<String> list = new JList<String>();
                list.setSize(listWidth, listHeight);
                DefaultListModel<String> listModel = new DefaultListModel<String>();
                listModel.add(selCellIndex, "E");
                list.setModel(listModel);
                list.setSelectedIndex(selCellIndex);

                BufferedImage img = new BufferedImage(listWidth, listHeight,
                    BufferedImage.TYPE_INT_ARGB);
                Graphics g = img.getGraphics();
                list.paint(g);
                g.dispose();

                Rectangle cellRect = list.getCellBounds(selCellIndex, selCellIndex);
                HashSet<Color> cellColors = new HashSet<Color>();
                int uniqueColorIndex = 0;
                for (int x = cellRect.x; x < (cellRect.x + cellRect.width); x++) {
                    for (int y = cellRect.y; y < (cellRect.y + cellRect.height); y++) {
                        Color cellColor = new Color(img.getRGB(x, y), true);
                        if (cellColors.add(cellColor)) {
                            System.err.println(String.format("Cell color #%d: %s",
                                uniqueColorIndex++, cellColor));
                        }
                    }
                }

                Color selForegroundColor = list.getSelectionForeground();
                Color selBackgroundColor = list.getSelectionBackground();
                if (!cellColors.contains(new Color(selForegroundColor.getRGB(), true))) {
                    throw new RuntimeException(String.format(
                        "Selected cell is drawn without selection foreground color '%s'.",
                        selForegroundColor));
                }
                if (!cellColors.contains(new Color(selBackgroundColor.getRGB(), true))) {
                    throw new RuntimeException(String.format(
                        "Selected cell is drawn without selection background color '%s'.",
                        selBackgroundColor));
                }
            }
        });
    } catch (UnsupportedLookAndFeelException | InterruptedException | InvocationTargetException e) {
        throw new RuntimeException(e);
    }
}
 
Example 19
Source File: JTreeFocusTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
public void destroy() throws Exception {
    SwingUtilities.invokeAndWait(()->fr.dispose());
    if ( !isPassed() ) {
        throw new RuntimeException("Focus wasn't transferred to the proper component");
    }
}
 
Example 20
Source File: ImageViewTest.java    From TencentKona-8 with GNU General Public License v2.0 2 votes vote down vote up
public static void main(String[] args) throws Exception {

        final String ABSOLUTE_FILE_PATH = ImageViewTest.class.getResource("circle.png").getPath();

        System.out.println(ABSOLUTE_FILE_PATH);

        Robot r = new Robot();

        final JEditorPane[] editorPanes = new JEditorPane[11];

        SwingUtilities.invokeAndWait(() -> {
            editorPanes[0] = new JEditorPane("text/html",
                    "<img height=\"200\" src=\"file:///" + ABSOLUTE_FILE_PATH + "\"");

            editorPanes[1] = new JEditorPane("text/html",
                    "<img width=\"200\" src=\"file:///" + ABSOLUTE_FILE_PATH + "\"");

            editorPanes[2] = new JEditorPane("text/html",
                    "<img width=\"200\" height=\"200\" src=\"file:///" + ABSOLUTE_FILE_PATH + "\"");

            editorPanes[3] = new JEditorPane("text/html",
                    "<img src=\"file:///" + ABSOLUTE_FILE_PATH + "\"");

            editorPanes[4] = new JEditorPane("text/html",
                    "<img width=\"100\" src =\"file:///" + ABSOLUTE_FILE_PATH + "\"");

            editorPanes[5] = new JEditorPane("text/html",
                    "<img height=\"100\" src =\"file:///" + ABSOLUTE_FILE_PATH + "\"");

            editorPanes[6] = new JEditorPane("text/html",
                    "<img width=\"100\" height=\"100\" src =\"file:///" + ABSOLUTE_FILE_PATH + "\"");

            editorPanes[7] = new JEditorPane("text/html",
                    "<img width=\"50\" src =\"file:///" + ABSOLUTE_FILE_PATH + "\"");

            editorPanes[8] = new JEditorPane("text/html",
                    "<img height=\"50\" src =\"file:///" + ABSOLUTE_FILE_PATH + "\"");

            editorPanes[9] = new JEditorPane("text/html",
                    "<img width=\"300\" src =\"file:///" + ABSOLUTE_FILE_PATH + "\"");

            editorPanes[10] = new JEditorPane("text/html",
                    "<img height=\"300\" src =\"file:///" + ABSOLUTE_FILE_PATH + "\"");

        });

        r.waitForIdle();

        System.out.println("Test with only height set to 200");
        test(r, editorPanes[0], 200, 200);

        System.out.println("Test with only width set to 200");
        test(r, editorPanes[1], 200, 200);

        System.out.println("Test with both of them set");
        test(r, editorPanes[2], 200, 200);

        System.out.println("Test with none of them set to 200");
        test(r, editorPanes[3], 200, 200);

        System.out.println("Test with only width set to 100");
        test(r, editorPanes[4], 100, 100);

        System.out.println("Test with only height set to 100");
        test(r, editorPanes[5], 100, 100);

        System.out.println("Test with both width and height set to 100");
        test(r, editorPanes[6], 100, 100);

        System.out.println("Test with only width set to 50");
        test(r, editorPanes[7], 50, 50);

        System.out.println("Test with only height set to 50");
        test(r, editorPanes[8], 50, 50);

        System.out.println("Test with only width set to 300");
        test(r, editorPanes[9], 300, 300);

        System.out.println("Test with only height set to 300");
        test(r, editorPanes[10], 300, 300);

        System.out.println("Test Passed.");
    }