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.setVisible(true); SwingUtilities.invokeLater( new Runnable() { public void run() { try {
((Timer)e.getSource()).stop(); Window win = SwingUtilities.getWindowAncestor(label); win.setVisible(false); SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGui();
gui.add(container, BorderLayout.CENTER); container.add(tb, BorderLayout.NORTH); for (int ii=0; ii<3; ii++) { tb.add(new JButton("Button")); SwingUtilities.invokeLater(new Runnable(){ @Override public void run() {
/** * Create the GUI and show it. For thread safety, this method should be invoked from the event * dispatch thread. */ public JFrame createAndShowGUI() { final JFrame frame = new JFrame("XChart Demo"); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); init(); // Schedule a job for the event dispatch thread: // creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater( new Runnable() { @Override public void run() { // Create and set up the window. // Add content to the window. frame.add(ExampleChartTester.this); // Display the window. frame.pack(); frame.setVisible(true); } }); return frame; }
import javax.swing.JFrame; import javax.swing.SwingUtilities; public class Test4 { protected static void initUI() { JFrame frame = new JFrame("test"); frame.setBounds(0, 0, 300, 200); frame.setVisible(true); System.err.println(frame.getSize()); frame.setResizable(false); System.err.println(frame.getSize()); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { initUI(); } }); } }
package com.stackoverflow.test; import java.net.URL; import javax.swing.*; // Wild carded for brevity. // Actual code imports single classes public class Main { public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable(){ public void run() { URL url = Main.class.getResource( "/resources/stackoverflow.png"); ImageIcon icon = new ImageIcon(url); JFrame frame = new JFrame(); frame.add(new JLabel(icon)); frame.pack(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocationRelativeTo(null); frame.setVisible(true); } }); } }
panel.add(label); SwingUtilities.invokeLater(new Runnable() { @Override public void run() {
public static void main(String args[]) { SwingUtilities.invokeLater(() -> { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); JDesktopPane desktopPane = new JDesktopPane(); DesktopManager dm = new MageDesktopManager(); desktopPane.setDesktopManager(dm); JInternalFrame internalFrame = new JInternalFrame("Test Internal Frame", true, false, true, true); internalFrame.setSize(200, 150); internalFrame.setVisible(true); desktopPane.add(internalFrame); frame.add(desktopPane, BorderLayout.CENTER); frame.setSize(800, 600); frame.setVisible(true); }); } }
JFrame frame = new JFrame(); frame.setTitle("Test Background"); frame.setLocation(200, 100); frame.setVisible(true); javax.swing.SwingUtilities.invokeLater(new Runnable() {
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();
this.getContentPane().add(mainPanel); SwingUtilities.invokeLater(new Runnable() {
JFrame frame = new JFrame("test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea textArea = new JTextArea(24, 80); textArea.setFont(new Font("monospaced", Font.PLAIN, 12)); frame.add(new JScrollPane(textArea)); frame.pack(); frame.setVisible(true); SwingUtilities.invokeLater(new Runnable() { @Override public void run() {
SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGui(); FieldTitle fieldTitle = FieldTitle.values()[i]; gbc = createGbc(0, i); add(new JLabel(fieldTitle.getTitle() + ":", JLabel.LEFT), gbc); gbc = createGbc(1, i); JTextField textField = new JTextField(10); add(textField, gbc);
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); JLabel imageLabel = new JLabel(ii); f.getContentPane().add(imageLabel); f.pack(); f.setLocationByPlatform(true); f.setVisible(true);
constraints.fill = GridBagConstraints.BOTH; JLabel l = new JLabel("You have got 2 new Messages."); panel.add(l, constraints); constraints.gridx++; constraints.weightx = 0f; b.setMargin(new Insets(1, 4, 1, 4)); b.setFocusable(false); panel.add(b, constraints); dialog.setUndecorated(true); dialog.setSize(300, 100); } catch (IllegalAccessException e) { SwingUtilities.invokeLater(new Runnable() {
final JFrame frame = new JFrame("Nested Layout Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); plafComponents.add(plafChooser); plafComponents.add(pack); SwingUtilities.updateComponentTreeUI(frame); if (pack.isSelected()) { frame.pack(); frame.setMinimumSize(frame.getSize()); gui.add(plafComponents, BorderLayout.NORTH); frame.pack(); frame.setVisible(true); SwingUtilities.invokeLater(r);
gui.add(l1); l2.setBackground(Color.YELLOW); l2.setOpaque(true); gui.add(l2); p1.add(new JLabel("Panel 1")); p1.setBorder(brdrRight); p1.setOpaque(false); SwingUtilities.invokeLater(r);
menuBar.add(createMenu("Menu 2")); menuBar.add(createMenu("Menu 3")); menuBar.add(new JSeparator()); menuBar.add(new JButton(" Seach .... ")); menuBar.add(new JTextField(" Seach .... ")); menuBar.add(new JComboBox(new Object[]{"height", "length", "volume"})); menuBar.add(Box.createHorizontalGlue()); menuBar.add(createMenu("About")); JFrame frame = new JFrame("MenuGlueDemo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(menuBar); frame.pack(); frame.setVisible(true); javax.swing.SwingUtilities.invokeLater(new Runnable() {
add(p); validate(); SwingUtilities.invokeLater(r); SwingUtilities.invokeLater(r); panel.add(output, BorderLayout.SOUTH); d = new Dimension(450,d.height); tableScroll.setPreferredSize(d); panel.add( tableScroll, BorderLayout.CENTER );
Runnable r = new Runnable() { public void run() { final JFrame f = new JFrame("Test Screenshot"); p.add( new JScrollPane(new JTree()), BorderLayout.WEST ); p.add( new JScrollPane( new JTextArea(HELP,10,30) ), BorderLayout.CENTER ); f.pack(); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true); SwingUtilities.invokeLater(r);