public boolean postProcessKeyEvent(KeyEvent ev) { if (ev.isConsumed()) return false; if (processShortcut(ev)) return true; Window w = SwingUtilities.windowForComponent(ev.getComponent()); if (w instanceof Dialog && !WindowManagerImpl.isSeparateWindow(w)) return false; JFrame mw = (JFrame)WindowManagerImpl.getInstance().getMainWindow(); if (w == mw) { return false; } JMenuBar mb = mw.getJMenuBar(); if (mb == null) return false; boolean pressed = (ev.getID() == KeyEvent.KEY_PRESSED); boolean res = invokeProcessKeyBindingsForAllComponents(ev, mw, pressed); if (res) ev.consume(); return res; }
private void getFittingMenubar(String mode) { JMenuBar jmb = new JMenuBar(); JMenuItem[][] menuItems = { { new JMenuItem(FI_FILE_NEW), null, new JMenuItem(FI_FILE_EXIT) }, { new JMenuItem(FI_HELP), null, new JMenuItem(FI_ABOUT) } }; String[] menuTitles = { "File", "Help" }; char[] chars = { 'F', 'e' }; for (int i = 0; i < menuItems.length; i++) { JMenu menu = new JMenu(menuTitles[i]); menu.setMnemonic(chars[i]); for (int j = 0; j < menuItems[i].length; j++) { if (menuItems[i][j] == null) { menu.addSeparator(); } else { menu.add(menuItems[i][j]); if (i == 0 && (j == 0 && mode.equals("demo"))) { menuItems[i][j].setEnabled(false); } } } jmb.add(menu); } setMenuBar(jmb); }
private static JFrame createGUI() { JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("Some menu"); menuBar.add(menu); for (int i = 0; i < 10; i++) { menu.add(new JMenuItem("Some menu #" + i)); } JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setMinimumSize(new Dimension(200, 200)); frame.setJMenuBar(menuBar); return frame; }
private void drawSelectedComponent(Graphics2D g2, JComponent selected, RADComponent rad) { if(selected == null) return; if(selected.getParent() == null || !selected.getParent().isVisible()) return; // draw normal border around toplevel menus if (selected instanceof JMenu && selected.getParent() instanceof JMenuBar) { JMenuItem menu = (JMenuItem) selected; Point location = SwingUtilities.convertPoint(menu, new Point(0, 0), this); g2.translate(location.x, location.y); // #114610: keep drop rectangle guidelines consistent when menu component is inserted from menu-bar into submenu g2.setStroke((currentTargetType == DropTargetType.INTO_SUBMENU) ? DROP_TARGET_LINE_STROKE : SELECTION_STROKE); g2.setColor(SELECTION_COLOR); g2.drawRect(0, 0, menu.getWidth() - 1, menu.getHeight() - 1); g2.translate(-location.x, -location.y); } // style only menuitems and menus that aren't also toplevel menus // don't do subrect drawing if doing a drag if (selected instanceof JMenuItem && !(selected.getParent() instanceof JMenuBar) && currentTargetComponent == null) { JMenuItem item = (JMenuItem) selected; drawSubselectedItem(g2, item); } }
void setDefaultMenuBar(final JMenuBar menuBar) { installDefaultMenuBar(menuBar); // scan the current frames, and see if any are foreground final Frame[] frames = Frame.getFrames(); for (final Frame frame : frames) { if (frame.isVisible() && !isFrameMinimized(frame)) { return; } } // if we have no foreground frames, then we have to "kick" the menubar final JFrame pingFrame = new JFrame(); pingFrame.getRootPane().putClientProperty("Window.alpha", Float.valueOf(0.0f)); pingFrame.setUndecorated(true); pingFrame.setVisible(true); pingFrame.toFront(); pingFrame.setVisible(false); pingFrame.dispose(); }
private void start(DropTargetDragEvent dtde) { PaletteItem item = PaletteUtils.getSelectedItem(); if(item != null && !isMenuRelatedComponentClass(item.getComponentClass())) { hideMenuLayer(); return; } if(formDesigner.getDesignerMode() == FormDesigner.MODE_ADD && item != null) { if(JMenuBar.class.isAssignableFrom(item.getComponentClass())) { hideMenuLayer(); return; } dragop.start(item,dtde.getLocation()); } }
/** Get MenuBar and tranfer it to ArrayList. * @param menu menu to be tranfered * @return tranfered menubar */ private static List<NbMenu> getMenuBarArrayList(JMenuBar menu) { visitMenuBar(menu); MenuElement [] elements = menu.getSubElements(); List<NbMenu> list = new ArrayList<NbMenu>(); for(int k=0; k < elements.length; k++) { // if(elements[k] instanceof JMenuItem) { // list.add(new NbMenu((JMenuItem)elements[k], null)); JMenuBarOperator menuOp = new JMenuBarOperator(menu); JMenu item = menuOp.getMenu(k); list.add(new NbMenu(item, getMenuArrayList(item))); // } /*if(elements[k] instanceof JMenuBar) { JMenuBarOperator menuOp = new JMenuBarOperator(menu); list.add(getMenuArrayList(menuOp.getMenu(0))); } */ } return list; }
@Override public void init() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { JMenuBar bar = new JMenuBar(); JMenu menu = new JMenu("Menu"); JCheckBoxMenuItem checkBoxMenuItem = new JCheckBoxMenuItem("JCheckBoxMenuItem"); checkBoxMenuItem.setSelected(true); menu.add(checkBoxMenuItem); bar.add(menu); setJMenuBar(bar); } }); } catch (Exception e) { throw new RuntimeException(e); } }
/** Open all menus in menubar * @param menu to be visited */ public static void visitMenuBar(JMenuBar menu) { MenuElement[] elements = menu.getSubElements(); JMenuBarOperator op = new JMenuBarOperator(menu); for (int k = 0; k < elements.length; k++) { if (elements[k] instanceof JMenuItem) { op.pushMenu(((JMenuItem) elements[k]).getText(), "/", true, true); try { op.wait(200); } catch (Exception e) { } } } }
/** Get MenuBar and tranfer it to ArrayList. * @param menu menu to be tranfered * @return tranfered menubar - !separator is ignored */ public static ArrayList<NbMenuItem> getMenuBarArrayList(JMenuBar menu) { // System.out.println("getMenuBarArrayList " + menu.getName()); visitMenuBar(menu); MenuElement[] elements = menu.getSubElements(); ArrayList<NbMenuItem> list = new ArrayList<NbMenuItem>(); for (int k = 0; k < elements.length; k++) { if (elements[k] instanceof JPopupMenu.Separator) { NbMenuItem separator = new NbMenuItem(); separator.setSeparator(true); list.add(separator); } else { if (elements[k] instanceof JMenuItem) { NbMenuItem item = new NbMenuItem((JMenuItem) elements[k]); JMenuBarOperator menuOp = new JMenuBarOperator(menu); item.setSubmenu(getMenuArrayList(menuOp.getMenu(k))); list.add(item); } } } return list; }
private void getTrafficMenubar() { JMenuBar jmb = new JMenuBar(); JMenuItem[][] menuItems = { { new JMenuItem(TR_FILE_NEW), null, new JMenuItem(TR_FILE_EXIT) }, { new JMenuItem(TR_HELP), null, new JMenuItem(TR_ABOUT) } }; String[] menuTitles = { "File", "Help" }; char[] chars = { 'F', 'e' }; for (int i = 0; i < menuItems.length; i++) { JMenu menu = new JMenu(menuTitles[i]); menu.setMnemonic(chars[i]); for (int j = 0; j < menuItems[i].length; j++) { if (menuItems[i][j] == null) { menu.addSeparator(); } else { menu.add(menuItems[i][j]); } } jmb.add(menu); } setMenuBar(jmb); }
/** * Creates workload analysis menu * @return menu */ public void makeMenubar() { workloadMenubar = new JMenuBar(); JMenuItem[][] menuItems = { { new JMenuItem(HELP),null,new JMenuItem(HELP_CREDITS) } }; String[] menuTitles = { "Help" }; char[] chars = { 'e' }; for (int i = 0; i < menuItems.length; i++) { JMenu menu = new JMenu(menuTitles[i]); menu.setMnemonic(chars[i]); for (int j = 0; j < menuItems[i].length; j++) { if (menuItems[i][j] == null) { menu.addSeparator(); } else { menu.add(menuItems[i][j]); } } workloadMenubar.add(menu); } parent.setMenuBar(workloadMenubar); }
public InputFrame(){ panel = new InputPanel(254); Container c = this.getContentPane(); c.setLayout(new BorderLayout()); c.add(new JScrollPane(panel), BorderLayout.CENTER); JButton jb = new JButton("Transfer"); //add menu bar JMenuBar jmb = new JMenuBar(); JMenu menu = new JMenu("File"); jmb.add(menu); initMenuItems(); //! da drin schreiben (und im InputPanel) menu.add(miSave); menu.add(miSaveAs); menu.add(miLoad); menu.addSeparator(); //! ...trennstrich im menü, dann dein item menu.add(miExport); this.setJMenuBar(jmb); }
@Override public JMenuBar createPeer() { final JMenuBar mb = new JMenuBar(); for (ChildProxy<?> child : children) { final JComponent peer = child.createPeer(); if (peer != null) mb.add(peer); } /* for (ButtonGroupProxy group : groups) { group.createPeer().setOwner(mb); } */ peers.add(new WeakReference<JMenuBar>(mb, queue)); return mb; }
private static void createAndShowGUI(TestItem testItem) { frame = new JFrame(); frame.setSize(300, 300); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar menuBar = new JMenuBar(); menu = new JMenu("Menu"); JMenuItem menuItem = testItem.getMenuItem(); testItem.setProperties(menuItem); menu.add(menuItem); menuBar.add(menu); frame.setJMenuBar(menuBar); frame.setVisible(true); }
/** * Creates workload analysis menu * @return menu */ public void makeMenubar() { workloadMenubar = new JMenuBar(); JMenuItem[][] menuItems = { { new JMenuItem(HELP_CREDITS) } }; String[] menuTitles = { "Help" }; char[] chars = { 'e' }; for (int i = 0; i < menuItems.length; i++) { JMenu menu = new JMenu(menuTitles[i]); menu.setMnemonic(chars[i]); for (int j = 0; j < menuItems[i].length; j++) { if (menuItems[i][j] == null) { menu.addSeparator(); } else { menu.add(menuItems[i][j]); } } workloadMenubar.add(menu); } parent.setMenuBar(workloadMenubar); }
/** * Constructor for cuttlefish * @param string filename of configuration file */ public Cuttlefish(String string) { super(); configFile = new File(string); menu = new JMenuBar(); if (!configFile.exists()) { configFile = Utils.createLocalFile("/ch/ethz/sg/cuttlefish/resources/default_configuration.xml", (Object) this); System.out.println("WARNING: configuration file not found - using default"); } initialize(); }
/** * Set up the menu bar */ JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); // File JMenu menuFile = new JMenu(textBundle.get("SwingAppleCommander.MenuFile")); //$NON-NLS-1$ // File->Open JMenuItem openItem = new JMenuItem(textBundle.get("SwingAppleCommander.MenuFileOpen")); //$NON-NLS-1$ openItem.addActionListener(this); menuFile.add(openItem); // File->Close JMenuItem closeItem = new JMenuItem(textBundle.get("SwingAppleCommander.MenuFileClose")); //$NON-NLS-1$ closeItem.addActionListener(this); menuFile.add(closeItem); // File->New JMenuItem newItem = new JMenuItem(textBundle.get("SwingAppleCommander.MenuFileNew")); //$NON-NLS-1$ newItem.addActionListener(this); menuFile.add(newItem); // File->Exit JMenuItem quitItem = new JMenuItem(textBundle.get("SwingAppleCommander.MenuFileQuit")); //$NON-NLS-1$ quitItem.addActionListener(this); menuFile.add(quitItem); menuBar.add(menuFile); return menuBar; }
public void displayAllInputs(){ // Add all the viewers for (int i=0; i<aeviewers.size(); i++) { AEViewer.Ambassador v=aeviewers.get(i); JPanel jp=new JPanel(); jp.setLayout(new BorderLayout()); jp.add(v.getPanel(),BorderLayout.CENTER); JMenuBar m=v.getToolBar(); // Disable spawning new windows inside here m.getMenu(0).getItem(0).setEnabled(false); jp.add(m,BorderLayout.NORTH); addDisplayWriter(jp,new Dimension(400,400)); refreshPlayingLocks(); v.setWatched(true); } resynchronize(); }
private void initializeMenus () { { JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); { JMenu fileMenu = new JMenu(); menuBar.add(fileMenu); fileMenu.setText("File"); fileMenu.setMnemonic(KeyEvent.VK_F); { openMenuItem = new JMenuItem("Open Hiero settings file..."); openMenuItem.setMnemonic(KeyEvent.VK_O); openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK)); fileMenu.add(openMenuItem); } { saveMenuItem = new JMenuItem("Save Hiero settings file..."); saveMenuItem.setMnemonic(KeyEvent.VK_S); saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_MASK)); fileMenu.add(saveMenuItem); } fileMenu.addSeparator(); { saveBMFontMenuItem = new JMenuItem("Save BMFont files (text)..."); saveBMFontMenuItem.setMnemonic(KeyEvent.VK_B); saveBMFontMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.CTRL_MASK)); fileMenu.add(saveBMFontMenuItem); } fileMenu.addSeparator(); { exitMenuItem = new JMenuItem("Exit"); exitMenuItem.setMnemonic(KeyEvent.VK_X); fileMenu.add(exitMenuItem); } } } }
public static void main( String[] args ) { // makes a MidiPlayer and MusicGenerators for later use MidiPlayer player = new MidiPlayer(); ArrayList<IMusicGenerator> musicGenList = new ArrayList<IMusicGenerator>(); IMusicGenerator canonGen = new CanonGenerator(player, new MelodyGenerator());//CanonGenerator mit standard MelodyGenerator IMusicGenerator fuge = new FugenGenerator(player, new FugenMelodyGenerator()); musicGenList.add(canonGen); musicGenList.add(fuge); //creates a new window and adds the standard components for this programm Window window = new Window(new FlowLayout(), player); //Panels CanonControllPanel ccP = new CanonControllPanel(canonGen, player, 3);//GeneratorControllPanel with 3 Instruments to choose window.add(ccP); window.add(new PlayerControllPanel(player)); //MenuLeiste ArrayList<ISongChangeObserver> scoList = new ArrayList<ISongChangeObserver>(); JMenuBar menuBar = new JMenuBar(); FileMenu fileMenu = new FileMenu(/*song*/ null, player, ccP); menuBar.add(fileMenu); scoList.add(fileMenu); menuBar.add(new GeneratorMenu(window, ccP, musicGenList, scoList)); window.setJMenuBar(menuBar); ccP.addSongChangeObserver(fileMenu); //stellt Fenster fertig window.pack(); }
void altPressed(KeyEvent ev) { MenuSelectionManager msm = MenuSelectionManager.defaultManager(); MenuElement[] path = msm.getSelectedPath(); if (path.length > 0 && ! (path[0] instanceof ComboPopup)) { msm.clearSelectedPath(); menuCanceledOnPress = true; ev.consume(); } else if(path.length > 0) { // We are in ComboBox menuCanceledOnPress = false; WindowsLookAndFeel.setMnemonicHidden(false); WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor); ev.consume(); } else { menuCanceledOnPress = false; WindowsLookAndFeel.setMnemonicHidden(false); WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor); JMenuBar mbar = root != null ? root.getJMenuBar() : null; if(mbar == null && winAncestor instanceof JFrame) { mbar = ((JFrame)winAncestor).getJMenuBar(); } JMenu menu = mbar != null ? mbar.getMenu(0) : null; if(menu != null) { ev.consume(); } } }
private static JMenuBar createMenuBar() { JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("File"); menuBar.add(menu); JMenuItem menuItem1 = new JMenuItem(" Save... "); menuItem1.addActionListener(std); menuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); menu.add(menuItem1); return menuBar; }
private String getComponentDefaultsPrefix(JComponent c) { if(c instanceof JMenuBar) { return "MenuBar"; // NOI18N } if(c instanceof JMenu) { return "Menu"; // NOI18N } if(c instanceof JCheckBoxMenuItem) { return "CheckBoxMenuItem"; // NOI18N } if(c instanceof JRadioButtonMenuItem) { return "RadioButtonMenuItem"; // NOI18N } return "MenuItem"; // NOI18N }
/** * Maps {@code JMenuBar.add(JMenu)} through queue */ public JMenu add(final JMenu jMenu) { return (runMapping(new MapAction<JMenu>("add") { @Override public JMenu map() { return ((JMenuBar) getSource()).add(jMenu); } })); }
/** * Maps {@code JMenuBar.isSelected()} through queue */ public boolean isSelected() { return (runMapping(new MapBooleanAction("isSelected") { @Override public boolean map() { return ((JMenuBar) getSource()).isSelected(); } })); }
public RADComponent getFormMenuBar() { for(RADComponent comp : formDesigner.getFormModel().getAllComponents()) { if(JMenuBar.class.isAssignableFrom(comp.getBeanClass())) { return comp; } } return null; }
@Override public void mouseEntered(MouseEvent e) { if(showMenubarWarning) { showMenubarWarning = false; repaint(); } if(dragop.isStarted()) { if(PaletteUtils.getSelectedItem() == null && dragop.isPickAndPlop()) { dragop.fastEnd(); } else { dragop.setTargetVisible(true); } } if(!dragop.isStarted() || PaletteUtils.getSelectedItem() != dragop.getCurrentItem()) { PaletteItem item = PaletteUtils.getSelectedItem(); // if not menu related at all, then jump back to handle layer if(item != null && !isMenuRelatedComponentClass(item.getComponentClass())) { hideMenuLayer(); return; } if(formDesigner.getDesignerMode() == FormDesigner.MODE_ADD && item != null) { if(JMenuBar.class.isAssignableFrom(item.getComponentClass())) { hideMenuLayer(); return; } dragop.start(item,e.getPoint()); } /* if(formDesigner.getDesignerMode() == FormDesigner.MODE_SELECT && showMenubarWarning) { //glassLayer.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); showMenubarWarning = false; repaint(); }*/ } }
/** * Maps {@code JMenuBar.getHelpMenu()} through queue */ public JMenu getHelpMenu() { return (runMapping(new MapAction<JMenu>("getHelpMenu") { @Override public JMenu map() { return ((JMenuBar) getSource()).getHelpMenu(); } })); }
public final JMenuBar createMenuBar() { JMenuBar result = new JMenuBar(); ContainerProvider cp = getContainerProvider(); String[] menus = cp.getMenuContainerContexts(); for (int i=0; i < menus.length; i++) { JMenu menu = getMenuFactory().createMenu(menus[i]); result.add (menu); } return result; }
public void createAndShowGUI() { frame = new JFrame("TEST"); JMenuBar mb = new JMenuBar(); menu = mb.add(createMenu("1 - First Menu", true)); mb.add(createMenu("2 - Second Menu", false)); frame.setJMenuBar(mb); JTextArea ta = new JTextArea("This test dedicated to Nancy and Kathleen, testers and bowlers extraordinaire\n\n\nNo exception means pass."); frame.getContentPane().add("Center", ta); JButton button = new JButton("Test"); frame.getContentPane().add("South", button); frame.setBounds(100, 100, 400, 400); frame.setVisible(true); button.requestFocusInWindow(); }
/** * Maps {@code JMenuBar.getMenuCount()} through queue */ public int getMenuCount() { return (runMapping(new MapIntegerAction("getMenuCount") { @Override public int map() { return ((JMenuBar) getSource()).getMenuCount(); } })); }
/** * Sets the default menu bar to use when there are no active frames. * * @param menuBar to use when no other frames are active * @throws SecurityException if a security manager exists and it denies the * {@code RuntimePermission("canProcessApplicationEvents")} permission. * @throws UnsupportedOperationException if the current platform * does not support the {@link Desktop.Action#APP_MENU_BAR} action * @since 9 */ public void setDefaultMenuBar(final JMenuBar menuBar) { checkEventsProcessingPermission(); checkActionSupport(Action.APP_MENU_BAR); if (menuBar != null) { Container parent = menuBar.getParent(); if (parent != null) { parent.remove(menuBar); menuBar.updateUI(); } } peer.setDefaultMenuBar(menuBar); }
/** * Maps {@code JMenuBar.menuSelectionChanged(boolean)} through queue */ public void menuSelectionChanged(final boolean b) { runMapping(new MapVoidAction("menuSelectionChanged") { @Override public void map() { ((JMenuBar) getSource()).menuSelectionChanged(b); } }); }
private static void createUI() { desktopPane = new JDesktopPane(); frame.getContentPane().add(desktopPane); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); menu = new JMenu("File"); menuBar.add(menu); menuItem = new JMenuItem("New Child"); menuItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JInternalFrame f = new JInternalFrame("Child " + (++count), true, true, true, true); f.setSize(200, 300); f.setLocation(count * 20, count * 20); desktopPane.add(f); f.setVisible(true); } }); menu.add(menuItem); frame.setSize(500, 500); frame.setLocationRelativeTo(null); frame.setVisible(true); }
@Override public void run() { final JMenuBar menubar = new JMenuBar(); menubar.add(new JMenu("")); menubar.add(new JMenu("")); final JFrame frame = new JFrame(); frame.setUndecorated(true); frame.setJMenuBar(menubar); frame.setSize(W / 3, H / 3); frame.setLocationRelativeTo(null); frame.setVisible(true); // draw menu bar using standard order. final BufferedImage bi1 = step1(menubar); // draw menu border on top of the menu bar, nothing should be changed. final BufferedImage bi2 = step2(menubar); frame.dispose(); for (int x = 0; x < W; ++x) { for (int y = 0; y < H; ++y) { if (bi1.getRGB(x, y) != bi2.getRGB(x, y)) { try { ImageIO.write(bi1, "png", new File("image1.png")); ImageIO.write(bi2, "png", new File("image2.png")); } catch (IOException e) { e.printStackTrace(); } throw new RuntimeException("Failed: wrong color"); } } } }
/** * Maps {@code JMenuBar.getMenu(int)} through queue */ public JMenu getMenu(final int i) { return (runMapping(new MapAction<JMenu>("getMenu") { @Override public JMenu map() { return ((JMenuBar) getSource()).getMenu(i); } })); }
public JMenuBar createMenuBar() { JMenuBar menuBar = null; FreeColClient client = new FreeColClient(null, null); client.startClient(null, null, true, true, null, null); //Create the menu bar. menuBar = new InGameMenuBar(client, null); client.updateActions(); ((FreeColMenuBar)menuBar).update(); return menuBar; }
@BeforeMethod public void showDialog() throws Throwable { SwingUtilities.invokeAndWait(new Runnable() { @Override public void run() { frame = new JFrame("My Dialog"); frame.setName("dialog-1"); JMenuBar menuBar = new JMenuBar(); menu = new JMenu("File"); menu.setMnemonic(KeyEvent.VK_F); menuBar.add(menu); exitItem = new JMenuItem("Exit"); menu.add(exitItem); frame.setJMenuBar(menuBar); Box box = new Box(BoxLayout.Y_AXIS); textField = new JTextField(""); box.add(textField); button = new JButton("Click Me!!"); box.add(button); new Timer().schedule(new TimerTask() { @Override public void run() { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JButton button1 = new JButton("Click Me Delayed!!"); button1.setName("click-me-delayed"); frame.getContentPane().add(button1); } }); } }, 1000); button.setName("click-me"); frame.setContentPane(box); frame.pack(); frame.setAlwaysOnTop(true); frame.setVisible(true); } }); driver = new JavaAgent(); }