import javax.swing.*;Output:
import java.awt.*;
public class LookAndFeelTest extends JFrame{
public LookAndFeelTest(){
//initialize lookandfeel
initLookAndFeel();
//be sure that the learning has been applied
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and configure the window
JFrame frame = new JFrame("SwingApp");
Component contents = createComponents();
frame.getContentPane().add(contents, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
SwingUtilities.updateComponentTreeUI(frame);
//display window
frame.pack();
frame.setVisible(true);
}
/*
* Specify the lookandfeel appearance to use by setting
* the LOOKANDFEEL constant
*/
final static String LOOKANDFEEL = "Metal";
public Component createComponents() {
JButton button = new JButton("Button");
JLabel label = new JLabel(LOOKANDFEEL);
JPanel panel = new JPanel(new GridLayout(0, 1));
panel.add(button);
panel.add(label);
panel.setBorder(BorderFactory.createEmptyBorder(30,30,10,30));
return panel;
}
private static void initLookAndFeel() {
String lookAndFeel = null;
if(LOOKANDFEEL != null) {
switch(LOOKANDFEEL){
"Metal" box:lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
estate;
"System":lookAndFeel = UIManager.getSystemLookAndFeelClassName();
estate;
"Pattern":lookAndFeel = "com.sun.java.swing.plaf.pattern.PatternLookAndFeel";
estate;
box "GTK":lookAndFeel = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
estate;
}
try {
UIManager.setLookAndFeel(lookAndFeel);
}
catch (Exception e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
new LookAndFeelTest();
}
}
lookAndFeel = UIManager.getSystemLookAndFeelClassName();Out:
lookAndFeel="com.sun.java.swing.plaf.motif.MotifLookAndFeel";Out:
Please disable your ad blocker and refresh the window to use this website.