JFrame f = new JFrame("Frame " + ii); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); String s = "os.name: " + System.getProperty("os.name") + "\nos.version: " + System.getProperty("os.version"); f.add(new JTextArea(s,3,28)); // suggest a size f.pack(); f.setLocationByPlatform(true); f.setVisible(true); SwingUtilities.invokeLater( new Runnable() { public void run() { try {
private static void setValue(final BoundedRangeModel model, final int val) { if (SwingUtilities.isEventDispatchThread()) { model.setValue(val); } else { SwingUtilities.invokeLater(new Runnable() { public void run() { model.setValue(val); } }); } } }
public void create(boolean waitFor){ if (SwingUtilities.isEventDispatchThread()) { initInEDT(); } else { try { if (waitFor) { try { SwingUtilities.invokeAndWait(new Runnable() { public void run() { initInEDT(); } }); } catch (InterruptedException ex) { listener.handleError("Interrupted", ex); } } else { SwingUtilities.invokeLater(new Runnable() { public void run() { initInEDT(); } }); } } catch (InvocationTargetException ex) { throw new AssertionError(); // can never happen } } }
@Override protected void repaint() { if(SwingUtilities.isEventDispatchThread()) { component.repaint(); } else { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { component.repaint(); } }); } }
@Override public void execute(Runnable command) { if (SwingUtilities.isEventDispatchThread()) { command.run(); return; } try { SwingUtilities.invokeAndWait(command); } catch (InterruptedException e) { throw new IllegalStateException(e); } catch (InvocationTargetException e) { throw new IllegalStateException(e); } } }
private JSpinner gravitySpinner; private JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BorderLayout()); draw = new DrawingArea(); mainPanel.add(draw, BorderLayout.CENTER); userInt = new JPanel(); mainPanel.add(userInt, BorderLayout.NORTH); SwingUtilities.invokeLater(new Runnable() { public void run() { JFrame window = new JFrame("Ball"); window.add(new StartingPoint().getMainPanel()); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.pack(); window.setLocationRelativeTo(null); window.setVisible(true);
SwingUtilities.invokeLater(new Runnable() { @Override public void run() { JFrame frame = new JFrame(); JPanel panel = new JPanel(); JLabel label = new JLabel("Loading..."); JProgressBar jpb = new JProgressBar(); int max = 1000; jpb.setMaximum(max); panel.add(label); panel.add(jpb); frame.add(panel); frame.pack(); frame.setSize(200,90); frame.setLocationRelativeTo(null); frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); new Task_IntegerUpdate(jpb, max, label).execute(); try { get(); JOptionPane.showMessageDialog(jpb.getParent(), "Success", "Success", JOptionPane.INFORMATION_MESSAGE); } catch (ExecutionException | InterruptedException e) { e.printStackTrace();
component.getWidth(), component.getHeight(), BufferedImage.TYPE_INT_RGB ); component.paint( image.getGraphics() ); // alternately use .printAll(..) return image; Runnable r = new Runnable() { public void run() { final JFrame f = new JFrame("Test Screenshot"); public void actionPerformed(ActionEvent ae) { BufferedImage img = getScreenShot( f.getContentPane() ); JOptionPane.showMessageDialog( null, JMenuBar mb = new JMenuBar(); mb.add(menu); f.setJMenuBar(mb); SwingUtilities.invokeLater(r);
final JFrame frame = new JFrame("Nested Layout Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JPanel gui = new JPanel(new BorderLayout(5,5)); gui.setBorder( new TitledBorder("BorderLayout(5,5)") ); plafComponents.add(plafChooser); plafComponents.add(pack); UIManager.setLookAndFeel( plafInfos[index].getClassName() ); SwingUtilities.updateComponentTreeUI(frame); if (pack.isSelected()) { frame.pack(); frame.setMinimumSize(frame.getSize()); gui.add(plafComponents, BorderLayout.NORTH); gui.add( splitPane, BorderLayout.CENTER ); frame.setContentPane(gui); frame.pack(); frame.setLocationRelativeTo(null); SwingUtilities.invokeLater(r);
l.setBorder(new LineBorder(Color.RED, 2)); return l; SwingUtilities.invokeLater(new Runnable() { public void run() { JPanel p = new JPanel(new GridLayout(2,2,4,4)); p.setBackground(Color.black); p.setBorder(new EmptyBorder(4,4,4,4)); JPanel border = new JPanel(new BorderLayout()); border.add(getLabel( "Border", SwingConstants.CENTER), BorderLayout.CENTER); p.add(border); JPanel gridbag = new JPanel(new GridBagLayout()); gridbag.add(getLabel("GridBag")); p.add(gridbag); p.add(box); JFrame f = new JFrame("Streeeetch me.."); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setContentPane(p); f.pack(); f.setLocationByPlatform(true); f.setVisible(true);
public static void main(String[] args) { JButton showWaitBtn = new JButton(new ShowWaitAction("Show Wait Dialog")); JPanel panel = new JPanel(); panel.add(showWaitBtn); JFrame frame = new JFrame("Frame"); frame.getContentPane().add(panel); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); Window win = SwingUtilities.getWindowAncestor((AbstractButton)evt.getSource()); final JDialog dialog = new JDialog(win, "Dialog", ModalityType.APPLICATION_MODAL); JPanel panel = new JPanel(new BorderLayout()); panel.add(progressBar, BorderLayout.CENTER); panel.add(new JLabel("Please wait......."), BorderLayout.PAGE_START); dialog.add(panel);
SwingUtilities.invokeAndWait(() -> ); container = new JPanel(); container.setLayout(new BoxLayout(container, BoxLayout.X_AXIS)); container.add(new ClientPanel(client)); navContainer = new JPanel(); titleBar.add(titleToolbar); LayoutManager delegate = titleBar.getLayout(); titleBar.setLayout(new LayoutManager() if (isOutdated) SwingUtilities.invokeLater(() -> JOptionPane.showMessageDialog(frame, "RuneLite has not yet been updated to work with the latest\n" + "game update, it will work with reduced functionality until then.",
JFrame frame = new JFrame(); JPanel panel = new JPanel(); frame.getContentPane().add(panel); panel.addKeyListener(new KeyListener() { panel.setFocusable(true); panel.requestFocusInWindow(); frame.setSize(new Dimension(300, 300)); frame.setVisible(true); SwingUtilities.invokeLater(r);
if (gui==null) { mainLayout = new BorderLayout(0,0); gui = new JPanel(mainLayout); gui.setBackground(Color.RED); border = new EmptyBorder(0,0,0,0); tree.expandRow(ii); JPanel buttonPanel = new JPanel(buttonLayout); gui.add(buttonPanel, BorderLayout.PAGE_START); buttonPanel.add(new JLabel("H Gap")); JFrame f = new JFrame("White (OK Red) Space"); f.add(gui); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.setLocationByPlatform(true); f.pack(); SwingUtilities.invokeLater(r);
this.ghostText = ghostText; this.ghostColor = Color.LIGHT_GRAY; textfield.addFocusListener(this); registerListeners(); updateState(); if (!this.textfield.hasFocus()) { focusLost(null); textfield.removeFocusListener(this); textfield.addPropertyChangeListener("foreground", this); try { textfield.setText(""); textfield.setForeground(foregroundColor); } finally { registerListeners(); try { textfield.setText(ghostText); textfield.setForeground(ghostColor); } finally { registerListeners(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() {
private JFrame frame = new JFrame(); setBackground(Color.gray); label.setOpaque(true); label.setBackground(Color.RED); label.setForeground(Color.WHITE); setBackground(Color.black); setLayout(new FlowLayout(FlowLayout.RIGHT)); add(label); addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent me) { frame.setLocation(frame.getLocation().x + me.getX() - pX, frame.getLocation().y + me.getY() - pY); public void mouseDragged(MouseEvent me) { frame.setLocation(frame.getLocation().x + me.getX() - pX, frame.getLocation().y + me.getY() - pY); SwingUtilities.invokeLater(new Runnable() { public void run() { new UndecoratedExample().createAnsShowGui();
topPanel = new JPanel(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLocationRelativeTo(null); tPane.setBorder(eb); topPanel.add(tPane); appendToPane(tPane, "flow", Color.ORANGE); getContentPane().add(topPanel); pack(); setVisible(true); SwingUtilities.invokeLater(new Runnable()
JLabel versionLabel = new JLabel("java.version=" + System.getProperty("java.version")); JLabel javaHomeLabel = new JLabel("java.home=" + System.getProperty("java.home")); setLayout(new BorderLayout()); add(versionLabel, BorderLayout.PAGE_START); add(javaHomeLabel, BorderLayout.PAGE_END); JFrame frame = new JFrame("MyJavaMacOSXApp"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); MyJavaMacOSXApp newContentPane = new MyJavaMacOSXApp(); newContentPane.setOpaque(true); frame.setContentPane(newContentPane); frame.pack(); frame.setVisible(true); javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI();
JFrame frame = new JFrame("FX"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().setLayout(null); // do the layout manually frame.add(jButton); frame.add(fxPanel); frame.setVisible(true); jButton.setSize(new Dimension(200, 27)); fxPanel.setSize(new Dimension(300, 300)); fxPanel.setLocation(new Point(0, 27)); frame.getContentPane().setPreferredSize(new Dimension(300, 327)); frame.pack(); frame.setResizable(false); SwingUtilities.invokeLater(new Runnable() { @Override public void run() {
SwingUtilities.invokeLater( new Runnable() { public void run() { + "The effect we want is a multi-line label."; JFrame f = new JFrame("Label Render Test"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); textLabel.setSize(textLabel.getPreferredSize()); Dimension d = textLabel.getPreferredSize(); BufferedImage bi = new BufferedImage( d.width, 10); g.setColor(Color.black); textLabel.paint(g); Graphics g2 = image.getGraphics(); g2.drawImage(bi, 20, 20, f); JLabel imageLabel = new JLabel(ii); f.getContentPane().add(imageLabel); f.pack(); f.setLocationByPlatform(true); f.setVisible(true);