Java Code Examples for javax.swing.UIManager#getCrossPlatformLookAndFeelClassName()

The following examples show how to use javax.swing.UIManager#getCrossPlatformLookAndFeelClassName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OSPRuntime.java    From osp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the look and feel of the user interface.  Look and feel user interfaces are:
 *
 * NIMBUS_LF: com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel
 * METAL_LF: javax.swing.plaf.metal.MetalLookAndFeel
 * GTK_LF: com.sun.java.swing.plaf.gtk.GTKLookAndFeel
 * MOTIF_LF: com.sun.java.swing.plaf.motif.MotifLookAndFeel
 * WINDOWS_LF: com.sun.java.swing.plaf.windows.WindowsLookAndFeel
 * DEFAULT_LF: the default look and feel in effect when this class was loaded
 * CROSS_PLATFORM_LF: the cross platform look and feel; usually METAL_LF
 * SYSTEM_LF: the operating system look and feel
 *
 * @param useDefaultLnFDecorations
 * @param lookAndFeel
 *
 * @return true if successful
 */
public static boolean setLookAndFeel(boolean useDefaultLnFDecorations, String lookAndFeel) {
  boolean found = true;
  LookAndFeel currentLookAndFeel = UIManager.getLookAndFeel();
  try {
    if((lookAndFeel==null)||lookAndFeel.equals(DEFAULT_LF)) {
      UIManager.setLookAndFeel(DEFAULT_LOOK_AND_FEEL);
      useDefaultLnFDecorations = DEFAULT_LOOK_AND_FEEL_DECORATIONS;
    } else if(lookAndFeel.equals(CROSS_PLATFORM_LF)) {
      lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
      UIManager.setLookAndFeel(lookAndFeel);
    } else if(lookAndFeel.equals(SYSTEM_LF)) {
      lookAndFeel = UIManager.getSystemLookAndFeelClassName();
      UIManager.setLookAndFeel(lookAndFeel);
    } else if(lookAndFeel.equals(NIMBUS_LF)) {
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");   //$NON-NLS-1$
    } else if(lookAndFeel.equals(METAL_LF)) {
      //        MetalLookAndFeel.setCurrentTheme(new DefaultMetalTheme());
      UIManager.setLookAndFeel(new MetalLookAndFeel());
    } else if(lookAndFeel.equals(GTK_LF)) {
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");         //$NON-NLS-1$
    } else if(lookAndFeel.equals(MOTIF_LF)) {
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");     //$NON-NLS-1$
    } else if(lookAndFeel.equals(WINDOWS_LF)) {
      UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); //$NON-NLS-1$
    } else {
      UIManager.setLookAndFeel(lookAndFeel);                                          // LnF can be set using a fully qualified path
    }
    JFrame.setDefaultLookAndFeelDecorated(useDefaultLnFDecorations);
    JDialog.setDefaultLookAndFeelDecorated(useDefaultLnFDecorations);
  } catch(Exception ex) {
    found = false;
  }
  if(!found) { // keep current look and feel
    try {
      UIManager.setLookAndFeel(currentLookAndFeel);
    } catch(Exception e) {}
  }
  return found;
}
 
Example 2
Source File: Main.java    From gate-core with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Reads the user config data and applies the required settings.
 * This must be called <b>after</b> {@link Gate#init()} but <b>before</b>
 * any GUI components are created.
 */
public static void applyUserPreferences(){
  //look and feel
  String lnfClassName;
  if(System.getProperty("swing.defaultlaf") != null) {
    lnfClassName = System.getProperty("swing.defaultlaf");
  } else {
    lnfClassName = Gate.getUserConfig().
                          getString(GateConstants.LOOK_AND_FEEL);
  }
  if(lnfClassName == null){
    //if running on Linux, default to Metal rather than GTK because GTK LnF
    //doesn't play nicely with most Gnome themes
    if(System.getProperty("os.name").toLowerCase().indexOf("linux") != -1){
      //running on Linux
      lnfClassName = UIManager.getCrossPlatformLookAndFeelClassName();
    }else{
      lnfClassName = UIManager.getSystemLookAndFeelClassName();
    }      
  }
  try {
    UIManager.setLookAndFeel(lnfClassName);
  } catch(Exception e) {
    System.err.print("Could not set your preferred Look and Feel. The error was:\n" +
            e.toString() + "\nReverting to using Java Look and Feel");
    try {
      UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
    }catch(Exception e1) {
      //we just can't catch a break here. Let's forget about look and feel.
      System.err.print(
              "Could not set the cross-platform Look and Feel either. The error was:\n" +
              e1.toString() + "\nGiving up on Look and Feel.");
    }
  }
  Gate.getUserConfig().put(GateConstants.LOOK_AND_FEEL, lnfClassName);
  
  //read the user config data
  OptionsMap userConfig = Gate.getUserConfig();

  //text font
  Font font = userConfig.getFont(GateConstants.TEXT_COMPONENTS_FONT);
  if(font == null){
    font = UIManager.getFont("TextPane.font");
  }

  if(font != null){
    OptionsDialog.setTextComponentsFont(font);
  }

  //menus font
  font = userConfig.getFont(GateConstants.MENUS_FONT);
  if(font == null){
    font = UIManager.getFont("Menu.font");
  }

  if(font != null){
    OptionsDialog.setMenuComponentsFont(font);
  }

  //other gui font
  font = userConfig.getFont(GateConstants.OTHER_COMPONENTS_FONT);
  if(font == null){
    font = UIManager.getFont("Button.font");
  }

  if(font != null){
    OptionsDialog.setComponentsFont(font);
  }

}