当前位置: 首页>>代码示例>>Java>>正文


Java EventQueue.invokeAndWait方法代码示例

本文整理汇总了Java中java.awt.EventQueue.invokeAndWait方法的典型用法代码示例。如果您正苦于以下问题:Java EventQueue.invokeAndWait方法的具体用法?Java EventQueue.invokeAndWait怎么用?Java EventQueue.invokeAndWait使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.awt.EventQueue的用法示例。


在下文中一共展示了EventQueue.invokeAndWait方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testDispatchEvent

import java.awt.EventQueue; //导入方法依赖的package包/类
public void testDispatchEvent() throws Exception {
    class Slow implements Runnable {
        private int ok;
        @Override
        public void run() {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                Exceptions.printStackTrace(ex);
            }
            ok++;
        }
    }
    Slow slow = new Slow();
    
    EventQueue.invokeAndWait(slow);
    EventQueue.invokeAndWait(slow);
    TimableEventQueue.RP.shutdown();
    TimableEventQueue.RP.awaitTermination(3, TimeUnit.SECONDS);
    
    assertEquals("called", 2, slow.ok);

    if (!log.toString().contains("too much time in AWT thread")) {
        fail("There shall be warning about too much time in AWT thread:\n" + log);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:TimableEventQueueTest.java

示例2: testSelectWithAdditionExisting

import java.awt.EventQueue; //导入方法依赖的package包/类
@RandomlyFails // got empty list of nodes in NB-Core-Build #3603
public void testSelectWithAdditionExisting() throws Exception {
    RootsTest.clearBareFavoritesTabInstance();
    TopComponent win = RootsTest.getBareFavoritesTabInstance();
    assertNull(win);
    fav.add(file);
    assertTrue(fav.isInFavorites(file));
    fav.selectWithAddition(file);
    win = RootsTest.getBareFavoritesTabInstance();
    assertNotNull(win);
    assertTrue(win.isOpened());
    assertTrue(fav.isInFavorites(file));
    EventQueue.invokeAndWait(new Runnable() {   // Favorites tab EM refreshed in invokeLater, we have to wait too

        public void run() {
            ExplorerManager man = ((ExplorerManager.Provider) RootsTest.getBareFavoritesTabInstance()).getExplorerManager();
            assertNotNull(man);
            Node[] nodes = man.getSelectedNodes();
            assertEquals(Arrays.toString(nodes), 1, nodes.length);
            assertEquals(TEST_TXT, nodes[0].getName());
        }

    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:FavoritesTest.java

示例3: captureWindows

import java.awt.EventQueue; //导入方法依赖的package包/类
/**
 * Captures each showing window image using Window.paint() method.
 */
private static void captureWindows() {
    try {
        EventQueue.invokeAndWait(() -> {
            Window[] windows = Window.getWindows();
            int index = 0;
            for (Window w : windows) {
                if (!w.isShowing()) {
                    continue;
                }
                BufferedImage img = new BufferedImage(w.getWidth(), w.getHeight(), BufferedImage.TYPE_INT_ARGB);
                Graphics g = img.getGraphics();
                w.paint(g);
                g.dispose();

                try {
                    ImageIO.write(img, "png", new File("window" + index++ + ".png"));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });
    } catch (InterruptedException | InvocationTargetException ex) {
        Logger.getLogger(JemmyExt.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:JemmyExt.java

示例4: isEnabled

import java.awt.EventQueue; //导入方法依赖的package包/类
private static boolean isEnabled(final Action a) throws Exception {
    final boolean[] ret = new boolean[1];
    EventQueue.invokeAndWait(new Runnable() {
        public void run() {
            ret[0] = a.isEnabled();
        }
    });
    return ret[0];
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:GlobalManagerTest.java

示例5: main

import java.awt.EventQueue; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    robot.setAutoDelay(50);

    EventQueue.invokeAndWait(() -> {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        JComboBox<String> comboBox = new JComboBox<>(new String[]{"one", "two"});
        comboBox.setEditable(true);
        comboBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                if ("comboBoxEdited".equals(e.getActionCommand())) {
                    isComboBoxEdited = true;
                }
            }
        });
        frame.add(comboBox);
        frame.pack();
        frame.setVisible(true);
        comboBox.requestFocusInWindow();
    });

    robot.waitForIdle();

    robot.keyPress(KeyEvent.VK_A);
    robot.keyRelease(KeyEvent.VK_A);
    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);
    robot.waitForIdle();

    if(!isComboBoxEdited){
        throw new RuntimeException("ComboBoxEdited event is not fired!");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:bug8057893.java

示例6: main

import java.awt.EventQueue; //导入方法依赖的package包/类
public static void main(String[] args) throws InterruptedException, java.lang.reflect.InvocationTargetException
{
    final Frame frame = new Frame("the test");
    frame.setLayout(new FlowLayout());
    final Button btn1 = new Button("button 1");
    frame.add(btn1);
    frame.add(new Button("button 2"));
    frame.add(new Button("button 3"));
    frame.pack();
    frame.setVisible(true);

    Robot r = Util.createRobot();
    Util.waitForIdle(r);
    Util.clickOnComp(btn1, r);
    Util.waitForIdle(r);
    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    if (kfm.getFocusOwner() != btn1) {
        throw new RuntimeException("test error: can not set focus on " + btn1 + ".");
    }

    EventQueue.invokeAndWait(new Runnable() {
            public void run() {
                final int n_comps = frame.getComponentCount();
                for (int i = 0; i < n_comps; ++i) {
                    frame.getComponent(i).setVisible(false);
                }
            }
        });
    Util.waitForIdle(r);
    final Component focus_owner = kfm.getFocusOwner();

    if (focus_owner != null && !focus_owner.isVisible()) {
        throw new RuntimeException("we have invisible focus owner");
    }
    System.out.println("test passed");
    frame.dispose();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:RequestFocusAndHideTest.java

示例7: testNextOnIterImplWithNotification

import java.awt.EventQueue; //导入方法依赖的package包/类
@RandomlyFails // NB-Core-Build #1429
public void testNextOnIterImplWithNotification () throws Exception {
    EventQueue.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            doNextOnIterImpl (true);
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:TemplateWizardTest.java

示例8: run

import java.awt.EventQueue; //导入方法依赖的package包/类
public void run() {
    // If there are no multiple input methods to choose from, wait forever
    while (!hasMultipleInputMethods()) {
        try {
            synchronized (this) {
                wait();
            }
        } catch (InterruptedException e) {
        }
    }

    // Loop for processing input method change requests
    while (true) {
        waitForChangeRequest();
        initializeInputMethodLocatorList();
        try {
            if (requestComponent != null) {
                showInputMethodMenuOnRequesterEDT(requestComponent);
            } else {
                // show the popup menu within the event thread
                EventQueue.invokeAndWait(new Runnable() {
                    public void run() {
                        showInputMethodMenu();
                    }
                });
            }
        } catch (InterruptedException ie) {
        } catch (InvocationTargetException ite) {
            // should we do anything under these exceptions?
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:ExecutableInputMethodManager.java

示例9: getPropertySets

import java.awt.EventQueue; //导入方法依赖的package包/类
@Override
public Node.PropertySet[] getPropertySets() {
    final Node.PropertySet[][] props = new Node.PropertySet[1][];
    Runnable runnable = new Runnable() {
        @Override
        public void run() {
            FormLAF.executeWithLAFLocks(new Runnable() {
                @Override
                public void run() {
                   props[0] = component.getProperties();
                }
            });
        }
    };
    if (EventQueue.isDispatchThread()) {
        runnable.run();
    } else {
        try {
            // We have made some attempts to keep initialization
            // of properties outside AWT thread, but it always
            // deadlocked with AWT thread for various reasons.
            EventQueue.invokeAndWait(runnable);
        } catch (InterruptedException iex) {
            FormUtils.LOGGER.log(Level.INFO, iex.getMessage(), iex);
        } catch (InvocationTargetException itex) {
            FormUtils.LOGGER.log(Level.INFO, itex.getMessage(), itex);
        }
    }
    return props[0];
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:RADComponentNode.java

示例10: waitEDT

import java.awt.EventQueue; //导入方法依赖的package包/类
private void waitEDT() throws Exception {
    EventQueue.invokeAndWait(new Runnable() {
        @Override
        public void run() {
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:NbErrorManagerUserQuestionTest.java

示例11: testUseCustomComparator

import java.awt.EventQueue; //导入方法依赖的package包/类
@Test
public void testUseCustomComparator() throws IOException,
        InterruptedException, InvocationTargetException {

    FileSystem fs = FileUtil.createMemoryFileSystem();

    fs.getRoot().createData("aaaa.txt");
    fs.getRoot().createData("bbb.txt");
    fs.getRoot().createData("cc.txt");
    fs.getRoot().createData("d.txt");
    fs.getRoot().refresh();

    DataFolder.SortMode custom = new DataFolder.SortMode() {
        @Override
        public int compare(DataObject o1, DataObject o2) {
            return o1.getName().length() - o2.getName().length();
        }
    };

    DataFolder df = DataFolder.findFolder(fs.getRoot());
    df.setSortMode(custom);
    EventQueue.invokeAndWait(new Runnable() {
        @Override
        public void run() {
        }
    });
    DataObject[] children = df.getChildren();
    assertEquals("d.txt", children[0].getName());
    assertEquals("cc.txt", children[1].getName());
    assertEquals("bbb.txt", children[2].getName());
    assertEquals("aaaa.txt", children[3].getName());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:FolderComparatorTest.java

示例12: testInAWT

import java.awt.EventQueue; //导入方法依赖的package包/类
public void testInAWT() throws Exception {
    EventQueue.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            doTestInAwt();
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:MenuBarFastFromAWTTest.java

示例13: testEnsureCaretPosition

import java.awt.EventQueue; //导入方法依赖的package包/类
/**
 * Test for bug 230402 - NullPointerException at
 * org.netbeans.core.output2.ui.AbstractOutputPane.run. No exception should
 * be thrown.
 *
 * @throws java.lang.InterruptedException
 * @throws java.lang.reflect.InvocationTargetException
 */
public void testEnsureCaretPosition() throws InterruptedException,
        InvocationTargetException {

    EventQueue.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            tab.setDocument(new HTMLDocument());
            tab.getOutputPane().run();
        }
    });
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:OutputTabTest.java

示例14: testIconIsAlwaysTakenFromSourceView

import java.awt.EventQueue; //导入方法依赖的package包/类
public void testIconIsAlwaysTakenFromSourceView() throws Exception {
       InstanceContent ic = new InstanceContent();
       Lookup lkp = new AbstractLookup(ic);
       ic.add(MultiViewEditorElementTest.createSupport(lkp));
       
       final CloneableTopComponent tc = MultiViews.createCloneableMultiView("text/plaintest", new LP(lkp));
       final CloneableEditorSupport.Pane p = (CloneableEditorSupport.Pane) tc;
       EventQueue.invokeAndWait(new Runnable() {
           @Override
           public void run() {
               p.updateName();
           }
       });

       assertNull("No icon yet", tc.getIcon());
       MultiViewHandler handler = MultiViews.findMultiViewHandler(tc);
       final MultiViewPerspective[] two = handler.getPerspectives();
       assertEquals("Two elements only" + Arrays.asList(two), 2, handler.getPerspectives().length);
       assertEquals("First one is source", "source", two[0].preferredID());
MultiViewDescription description = Accessor.DEFAULT.extractDescription(two[0]);
assertTrue(description instanceof ContextAwareDescription);
       assertFalse("First one is not for split", ((ContextAwareDescription)description).isSplitDescription());
       assertEquals("Second one is source", "source", two[1].preferredID());
description = Accessor.DEFAULT.extractDescription(two[1]);
assertTrue(description instanceof ContextAwareDescription);
       assertTrue("Second one is for split", ((ContextAwareDescription)description).isSplitDescription());
       handler.requestVisible(two[0]);
       
       
       class P implements PropertyChangeListener {
           int cnt;
           @Override
           public void propertyChange(PropertyChangeEvent evt) {
               cnt++;
           }
       }
       P listener = new P();
       tc.addPropertyChangeListener("icon", listener);
       
       BufferedImage img = new BufferedImage(16, 16, BufferedImage.TYPE_BYTE_GRAY);
       ic.add(img);
       assertEquals("One change in listener", 1, listener.cnt);
       assertEquals("Image changed", img, tc.getIcon());
       
       ic.remove(img);
       assertEquals("Second change in listener", 2, listener.cnt);
       assertNull("No icon again", tc.getIcon());

((MultiViewCloneableTopComponent)tc).splitComponent(JSplitPane.HORIZONTAL_SPLIT, -1);
handler.requestVisible(two[1]);
       ic.add(img);
       assertEquals("Third change in listener", 3, listener.cnt);
       assertEquals("Image changed", img, tc.getIcon());

ic.remove(img);
       assertEquals("Forth change in listener", 4, listener.cnt);
       assertNull("No icon again", tc.getIcon());
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:59,代码来源:MultiViewProcessorTest.java

示例15: testCloneModifyClose

import java.awt.EventQueue; //导入方法依赖的package包/类
@RandomlyFails () // NB-Core-Build #9365: Unstable
public void testCloneModifyClose() throws Exception {
    InstanceContent ic = new InstanceContent();
    Lookup context = new AbstractLookup(ic);
    
    final CES ces = createSupport(context, ic);
    ic.add(ces);
    ic.add(10);
    
    EventQueue.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            ces.open();
        }
    });
    final CloneableTopComponent tc = (CloneableTopComponent) ces.findPane();
    assertNotNull("Component found", tc);
    final CloneableTopComponent tc2 = tc.cloneTopComponent();
    EventQueue.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            tc2.open();
            tc2.requestActive();
        }
    });
    
    ces.openDocument();
    
    EventQueue.invokeAndWait(new Runnable() {
        @Override
        public void run() {
            assertEquals("Two panes are open", 2, ces.getOpenedPanes().length);
        }
    });
    
    StyledDocument doc = ces.getDocument();
    assertNotNull("Document is opened", doc);
    doc.insertString(0, "Ahoj", null);
    assertTrue("Is modified", ces.isModified());
    
    assertNotNull("Savable present", tc.getLookup().lookup(Savable.class));
    assertNotNull("Savable present too", tc2.getLookup().lookup(Savable.class));
    
    assertTrue("First component closes without questions", tc.close());
    
    Savable save3 = tc2.getLookup().lookup(Savable.class);
    assertNotNull("Savable still present", save3);
    
    save3.save();
    
    assertEquals("Saved", "Ahoj", Env.LAST_ONE.output);
    assertTrue("Can be closed without problems", tc2.close());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:54,代码来源:MultiViewEditorCloneTest.java


注:本文中的java.awt.EventQueue.invokeAndWait方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。