當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。