Kod jest bardzo prosty i mam nadzieję że zrozumiały ale jeśli ktoś go dopracuje to proszę o kontakt [email protected]. Dobra to kod:
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
System.out.println(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(to jest aby odświeżyć komponent napisz tu nazwę komponentu);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
A tu jest prosty przykład:
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.geom.Area;
import java.util.Scanner;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
import javax.swing.JEditorPane;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JInternalFrame.JDesktopIcon;
import javax.swing.JLabel;
import javax.swing.JLayer;
import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JWindow;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
public class tester {
static JRadioButton jrb1 = new JRadioButton("test");
static JFrame F=new JFrame("Test");
static JPanel P=new JPanel();
static JColorChooser C=new JColorChooser();
static JTextField area=new JTextField(4);
static JButton button1=new JButton("Code");
static JTextArea jta = new JTextArea(5,5);
static JTextField jtf = new JTextField(5);
static JComboBox jcb = new JComboBox();
static JMenuBar jmb = new JMenuBar();
static JMenu jm1 = new JMenu("Test");
static JLabel enemy=new JLabel();
public static void main(String args[]) {
F.setSize(1024, 200);
F.setDefaultCloseOperation(3);
try {
Thread.sleep(1);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
F.setVisible(true);
F.add(P);
P.setBackground(Color.magenta);
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
System.out.println(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(button1);
SwingUtilities.updateComponentTreeUI(jrb1);
SwingUtilities.updateComponentTreeUI(C);
SwingUtilities.updateComponentTreeUI(jta);
SwingUtilities.updateComponentTreeUI(jtf);
SwingUtilities.updateComponentTreeUI(jcb);
SwingUtilities.updateComponentTreeUI(jmb);
SwingUtilities.updateComponentTreeUI(jm1);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
jmb.add(jm1);
F.setJMenuBar(jmb);
P.add(button1);
P.add(C);
P.add(jrb1);
P.add(jta);
P.add(jtf);
P.add(jcb);
}
}
Ten oto kod nie tylko działa na windowsie ale na wszystkich systemach obsługujących jave