Java - AWT/Swing

Carry out actions after GUI-update

com.javax.SwingUtilities
At Swing the same thread is responsible for drawing the surface new and working off the events. This is especially unpleasant, if a rake-intensive operation is activated by pressing a button. This results in that the button seems to be pressed as long as the operation continues. The GUI seems to be freezed up until the operation is finished.



Here, the SwingUtilities offer two methods: invokeLater and invokeAndWait.
invokeLater works out of synch, so the program keeps running.
invokeAnWait however, waits until the operation is finished.

public void actionPerformed(ActionEvent e){
   try{
      SwingUtilities.invokeLater(new Runnable(){
         public void run() { 
            // Here listed code is carried out after the GUI-update.
         }
      });
   }catch (Exception ex){
      ex.printStackTrace();
   }
}



Eigene Werkzeuge
Werkzeuge

gratis Counter by GOWEB
seit 9.10.2007