Friday, June 29, 2007

HOWTO: properly start a Java Swing Application from main

Overview
When starting a JAVA Swing application, is is not always clear on the proper way to fire it up. If you use Netbeans, it provides you with a nice stub in main for doing this.

Technique
To start a JAVA Swing application...

public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
UIManager.put("swing.boldMetal", Boolean.FALSE);
new JListStripingForm().setVisible(true);
}
});
}
The UIManager.put(...) line turns off the BOLD for all menus and such. I think it makes the program look bad.

The rest ensures that the application starts on the correct thread and makes the application visible.

Final Thoughts
This can be used to ensure a smooth startup of a Swing application.

1 comment:

javac said...

This worked
Earlier I could not see anything unless i resize the window.Now I can see elements on window quickly
Just the black blink on the screen makes it look bad.
But thanks