Look and Feel - Java Swing


Written on January 4, 2008 – 3:17 am | by André Gomes

While i’m programming an application on Java using Swing package on NetBeans IDE 6.0, i build a Form file and after that, i didn’t like very much the appearance of that window.

The theme that it use by default is the Metal theme.

So, if you want to change the appearance of a Java Swing application follow the example:

(In your TestForm.java form, put the code) :

public class TestForm extends javax.swing.JFrame
{
         public static void main(String args[]) {
         java.awt.EventQueue.invokeLater(new Runnable() {
              public void run() {
                  try
                  {
                      UIManager.setLookAndFeel("com.sun.java." +
                      "swing.plaf.windows.WindowsLookAndFeel");
                  }
                  catch(Exception e)
                  {
                      e.printStackTrace();
                  }
                  new TestForm().setVisible(true);
              }
         });
         }
}

So if you use this code in your Main window, every form which is called by that have the same theme you selected here.

I can’t ident the code, Wordpress have a lot of problems doing that, if anybody help me…



Veja também:

Tags: , ,

  1. 3 Responses to “Look and Feel - Java Swing”

  2. By nunojob on Jan 4, 2008 | Reply

    Parece que não posso usar o >pre< :P

  3. By nunojob on Jan 4, 2008 | Reply

    Xissa tou mesmo trengo:

    <pre>

  4. By Gustavo on Aug 11, 2008 | Reply

    http://code.google.com/p/easylookandfeel/

    Esse componente é bem bacana. Com ele você consegue não só usar o skin padrão do sistema, como também fornecer ao usuário a opção de escolher o skin que deseja.

    Abraços.

Post a Comment