javax.swing.SwingUtilities#invokeAndWait ( )源码实例Demo

下面列出了javax.swing.SwingUtilities#invokeAndWait ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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 )
	{}
}
 
源代码2 项目: dragonwell8_jdk   文件: DashStrokeTest.java
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);
        }
}
 
源代码3 项目: marathonv5   文件: JavaDriverTest.java
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();
    }
}
 
源代码4 项目: openjdk-jdk9   文件: PageDialogMarginValidation.java
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");
    }
}
 
源代码5 项目: openjdk-jdk8u-backup   文件: MissingCharsKorean.java
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");
    }
}
 
源代码6 项目: TencentKona-8   文件: bug8034955.java
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);
        }
    });
}
 
源代码7 项目: marathonv5   文件: RColorChooserTest.java
@AfterMethod
public void disposeDriver() throws Throwable {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setVisible(false);
            frame.dispose();
        }
    });
}
 
源代码8 项目: marathonv5   文件: JavaDriverTest.java
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"));
}
 
源代码9 项目: marathonv5   文件: JavaDriverTest.java
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"));
}
 
源代码10 项目: netbeans   文件: FocusAfterBadEditTest.java
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();
}
 
源代码11 项目: runelite   文件: SplashScreen.java
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);
	}
}
 
源代码12 项目: marathonv5   文件: JTableTest.java
@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);
        }
    });
}
 
源代码13 项目: netbeans   文件: RendererDisplayerTest.java
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();
}
 
源代码14 项目: marathonv5   文件: NativeEventsTest.java
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());

}
 
源代码15 项目: marathonv5   文件: JInternalFrameTest.java
@AfterMethod
public void disposeDriver() throws Throwable {
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            frame.setVisible(false);
            frame.dispose();
        }
    });
    if (driver != null) {
        driver.quit();
    }
}
 
源代码16 项目: openjdk-jdk9   文件: JTreeFocusTest.java
public void destroy() throws Exception {
    SwingUtilities.invokeAndWait(()->fr.dispose());
    if ( !isPassed() ) {
        throw new RuntimeException("Focus wasn't transferred to the proper component");
    }
}
 
源代码17 项目: TencentKona-8   文件: bug8057791.java
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);
    }
}
 
源代码18 项目: openjdk-8-source   文件: Test7024235.java
private void test() throws Exception {
    SwingUtilities.invokeAndWait(this);
    if (!this.passed && AUTO) { // error reporting only for automatic testing
        throw new Error("TEST FAILED");
    }
}
 
源代码19 项目: netbeans   文件: PluginManagerActionTest.java
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 ());
}
 
源代码20 项目: TencentKona-8   文件: ImageViewTest.java
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.");
    }