UIManager改变

UIManager改变

 class ControlPanel extends JPanel {
  JCheckBox checkBox = new JCheckBox("UIResource");

  JRadioButton motifButton = new JRadioButton("Motif"),
    windowsButton = new JRadioButton("Windows"),
    metalButton = new JRadioButton("Metal");

  public ControlPanel() {
   ActionListener listener = new RadioHandler();
   ButtonGroup group = new ButtonGroup();

   group.add(motifButton);
   group.add(windowsButton);
   group.add(metalButton);

   motifButton.addActionListener(listener);
   windowsButton.addActionListener(listener);
   metalButton.addActionListener(listener);

   add(motifButton);
   add(windowsButton);
   add(metalButton);
  }

  class RadioHandler implements ActionListener {
   public void actionPerformed(ActionEvent e) {
    JRadioButton src = (JRadioButton) e.getSource();

    try {
     if (src == motifButton)
      UIManager.setLookAndFeel("com.sun.java.swing.plaf."
        + "motif.MotifLookAndFeel");

     else if (src == windowsButton)
      UIManager.setLookAndFeel("com.sun.java.swing.plaf."
        + "windows.WindowsLookAndFeel");

     else if (src == metalButton)
      UIManager.setLookAndFeel("javax.swing.plaf.metal."
        + "MetalLookAndFeel");
    } catch (Exception ex) {
     ex.printStackTrace();
    }
    SwingUtilities.updateComponentTreeUI(getContentPane());
   }
  }
 }

你可能感兴趣的:(UIManager改变)