Home
Categories
Dictionary
Download
Project Details
Changes Log
FAQ
License

MacOSXUISetter



The MacOSXUISetter and SwingMacOSXUISetter classes allow to:
  • Set the menus on the top of the screen
  • Set the application name
  • Set the Mac OS X Look and Feel


Note that these classes won't perform anything if the platform is not Mac OS X.
Note that you must call these classes before you are using any Swing classes, including Swing constructors.

MacOSXUISetter

The MacOSXUISetter.setMacOSXMenus(String) static method allows to:
  • Set the menus on the top of the screen as it is customary for Mac OS X applications

You don't need to use the Swing UI framework to use this class.

SwingMacOSXUISetter

The SwingMacOSXUISetter.setNativePlatformUI(String, boolean) static method allows to:
  • Set the menus on the top of the screen
  • Set the application name
  • Set the Mac OS X Look and Feel

You need to use the Swing UI framework to use this class.

Example

The following code:
   public static void main(String arg[]) {
      SwingMacOSXUISetter.setNativePlatformUI("Test MAC OS", true);
      JFrame f = new JFrame("test");

      JMenuBar mbar = new JMenuBar();
      f.setJMenuBar(mbar);
      JMenu menu = new JMenu("File");
      mbar.add(menu);
      menu.add(new JMenuItem("Open"));
      menu.add(new JMenuItem("Exit"));

      menu = new JMenu("Actions");
      mbar.add(menu);
      menu.add(new JMenuItem("Do Something"));

      Container pane = f.getContentPane();
      pane.setLayout(new BoxLayout(pane, BoxLayout.Y_AXIS));

      JPanel xpane = new JPanel();
      pane.add(xpane);
      xpane.setLayout(new BoxLayout(xpane, BoxLayout.X_AXIS));
      xpane.add(Box.createHorizontalStrut(5));
      xpane.add(new JFileSelector());
      xpane.add(Box.createHorizontalStrut(5));
      xpane.add(Box.createHorizontalGlue());

      pane.add(Box.createVerticalStrut(5));
      xpane = new JPanel();
      pane.add(xpane);
      xpane.setLayout(new BoxLayout(xpane, BoxLayout.X_AXIS));
      xpane.add(Box.createHorizontalStrut(5));
      xpane.add(new JButton("Click Me!"));
      xpane.add(new JColorSelector());
      xpane.add(Box.createHorizontalGlue());
      pane.add(LayoutUtils.createGreedyVerticalGlue());

      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      f.setSize(400, 300);
      f.setVisible(true);
Has the following result on Mac OS X:
macos

Categories: lang | packages | swing

Copyright 2006-2024 Herve Girod. All Rights Reserved. Documentation and source under the LGPL v2 and Apache 2.0 licences