使用自定義 LF
public class CustomLookAndFeel
{
public static void main ( final String[] args )
{
// L&F installation should be performed within EDT (Event Dispatch Thread)
// This is important to avoid any UI issues, exceptions or even deadlocks
SwingUtilities.invokeLater ( new Runnable ()
{
@Override
public void run ()
{
// Process of L&F installation might throw multiple exceptions
// It is always up to you whether to handle or ignore them
// In most common cases you would never encounter any of those
try
{
// Installing custom L&F as a current application L&F
UIManager.setLookAndFeel ( "javax.swing.plaf.metal.MetalLookAndFeel" );
}
catch ( final ClassNotFoundException e )
{
// L&F class was not found
e.printStackTrace ();
}
catch ( final InstantiationException e )
{
// Exception while instantiating L&F class
e.printStackTrace ();
}
catch ( final IllegalAccessException e )
{
// Class or initializer isn't accessible
e.printStackTrace ();
}
catch ( final UnsupportedLookAndFeelException e )
{
// L&F is not supported on the current system
e.printStackTrace ();
}
// Now we can create some pretty-looking UI
// This is just a small sample frame with a single button on it
final JFrame frame = new JFrame ();
final JPanel content = new JPanel ( new FlowLayout () );
content.setBorder ( BorderFactory.createEmptyBorder ( 50, 50, 50, 50 ) );
content.add ( new JButton ( "Metal button" ) );
frame.setContentPane ( content );
frame.setDefaultCloseOperation ( WindowConstants.EXIT_ON_CLOSE );
frame.pack ();
frame.setLocationRelativeTo ( null );
frame.setVisible ( true );
}
} );
}
}
你可以在這裡找到一個龐大的可用 Swing L&F 列表: Java 外觀(L&F)
請記住,其中一些 L&F 可能在這一點上已經過時了。