コード例 #1
0
 public static JMenu createLookAndFeelMenu() {
   JMenu menu = new JMenu("LookAndFeel");
   ButtonGroup lookAndFeelRadioGroup = new ButtonGroup();
   for (UIManager.LookAndFeelInfo lafInfo : UIManager.getInstalledLookAndFeels()) {
     menu.add(
         createLookAndFeelItem(lafInfo.getName(), lafInfo.getClassName(), lookAndFeelRadioGroup));
   }
   return menu;
 }
コード例 #2
0
 private static void setLookAndFeel(String lookAndFeel)
     throws ClassNotFoundException, InstantiationException, IllegalAccessException,
         UnsupportedLookAndFeelException {
   String oldLookAndFeel = LookAndFeelUtil.lookAndFeel;
   if (!oldLookAndFeel.equals(lookAndFeel)) {
     UIManager.setLookAndFeel(lookAndFeel);
     LookAndFeelUtil.lookAndFeel = lookAndFeel;
     updateLookAndFeel();
     // firePropertyChange("lookAndFeel", oldLookAndFeel, lookAndFeel);
   }
 }
コード例 #3
0
  public static void createAndShowGUI() {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException
        | InstantiationException
        | IllegalAccessException
        | UnsupportedLookAndFeelException ex) {
      ex.printStackTrace();
    }
    // UIManager.put("AuditoryCues.playList", UIManager.get("AuditoryCues.allAuditoryCues"));
    // UIManager.put("AuditoryCues.playList", UIManager.get("AuditoryCues.defaultCueList"));
    // UIManager.put("AuditoryCues.playList", UIManager.get("AuditoryCues.noAuditoryCues"));
    UIManager.put("AuditoryCues.playList", OPTION_PANE_AUDITORY_CUES);
    // UIManager.put("OptionPane.informationSound", "/example/notice2.wav");
    // UIManager.put("OptionPane.informationSound", "sounds/OptionPaneError.wav");
    // System.out.println(UIManager.get("AuditoryCues.actionMap"));

    JFrame frame = new JFrame("@title@");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.getContentPane().add(new MainPanel());
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
コード例 #4
0
// http://java.net/projects/swingset3/sources/svn/content/trunk/SwingSet3/src/com/sun/swingset3/SwingSet3.java
final class LookAndFeelUtil {
  private static String lookAndFeel = UIManager.getLookAndFeel().getClass().getName();

  private LookAndFeelUtil() {
    /* Singleton */
  }

  public static JMenu createLookAndFeelMenu() {
    JMenu menu = new JMenu("LookAndFeel");
    ButtonGroup lookAndFeelRadioGroup = new ButtonGroup();
    for (UIManager.LookAndFeelInfo lafInfo : UIManager.getInstalledLookAndFeels()) {
      menu.add(
          createLookAndFeelItem(lafInfo.getName(), lafInfo.getClassName(), lookAndFeelRadioGroup));
    }
    return menu;
  }

  private static JRadioButtonMenuItem createLookAndFeelItem(
      String lafName, String lafClassName, final ButtonGroup lookAndFeelRadioGroup) {
    JRadioButtonMenuItem lafItem = new JRadioButtonMenuItem();
    lafItem.setSelected(lafClassName.equals(lookAndFeel));
    lafItem.setHideActionText(true);
    lafItem.setAction(
        new AbstractAction() {
          @Override
          public void actionPerformed(ActionEvent e) {
            ButtonModel m = lookAndFeelRadioGroup.getSelection();
            try {
              setLookAndFeel(m.getActionCommand());
            } catch (ClassNotFoundException
                | InstantiationException
                | IllegalAccessException
                | UnsupportedLookAndFeelException ex) {
              ex.printStackTrace();
            }
          }
        });
    lafItem.setText(lafName);
    lafItem.setActionCommand(lafClassName);
    lookAndFeelRadioGroup.add(lafItem);
    return lafItem;
  }

  private static void setLookAndFeel(String lookAndFeel)
      throws ClassNotFoundException, InstantiationException, IllegalAccessException,
          UnsupportedLookAndFeelException {
    String oldLookAndFeel = LookAndFeelUtil.lookAndFeel;
    if (!oldLookAndFeel.equals(lookAndFeel)) {
      UIManager.setLookAndFeel(lookAndFeel);
      LookAndFeelUtil.lookAndFeel = lookAndFeel;
      updateLookAndFeel();
      // firePropertyChange("lookAndFeel", oldLookAndFeel, lookAndFeel);
    }
  }

  private static void updateLookAndFeel() {
    for (Window window : Frame.getWindows()) {
      SwingUtilities.updateComponentTreeUI(window);
    }
  }
}