SwingUtilities: invokeAndWait(Runnable run) : SwingUtilities « javax.swing « Java by API






SwingUtilities: invokeAndWait(Runnable run)

  
import java.awt.Component;
import java.awt.Graphics;

import javax.swing.Icon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

public class MainClass extends JPanel {

  public MainClass() {
    try {
      SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
          JLabel jl = new JLabel(new MyIcon(), JLabel.CENTER);
          add(jl);
        }
      });
    } catch (Exception exc) {
      System.out.println("Can't create because of " + exc);
    }
  }

  public static void main(String[] args) {
    JFrame frame = new JFrame();
    frame.getContentPane().add(new MainClass());

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(200, 200);
    frame.setVisible(true);
  }

}

           
         
    
  








Related examples in the same category

1.SwingUtilities: convertPointFromScreen(Point p, Component c)
2.SwingUtilities: convertPointToScreen(Point p, Component c)
3.SwingUtilities: getRoot(Component c)
4.SwingUtilities: getWindowAncestor(Component c)
5.SwingUtilities.invokeLater(Runnable doRun)
6.SwingUtilities.isEventDispatchThread()
7.SwingUtilities.isLeftMouseButton(MouseEvent mouseEvent)
8.SwingUtilities.isMiddleMouseButton(MouseEvent mouseEvent)
9.SwingUtilities.isRightMouseButton(MouseEvent mouseEvent)
10.SwingUtilities: updateComponentTreeUI(Component c)