1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class main {
static Frame frame ;
public static void main(String[] args) {
frame = new Frame() ;
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class Frame extends JFrame {
public Frame() {
setSize(400,400);
setTitle("Test");
JMenu Look = new JMenu("Look");
JMenuBar menuBar = new JMenuBar();
setJMenuBar(menuBar);
menuBar.add(Look);
MenuItem pane = new MenuItem(Look);
}
}
class MenuItem extends JPanel {
public MenuItem(JMenu look) {
UIManager.LookAndFeelInfo[] infos = UIManager.getInstalledLookAndFeels();
for( UIManager.LookAndFeelInfo info : infos ) {
makeButton( look, info.getName(), info.getClassName());
}
}
void makeButton(JMenu look, String name, final String Look) {
JMenuItem menuItem = new JMenuItem(name);
look.add(menuItem);
menuItem.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent event) {
try {
UIManager.setLookAndFeel( Look );
SwingUtilities.updateComponentTreeUI(main.frame);
}
catch(Exception e) {}
}
}
);
}
} |
Partager