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

The following examples show how to use javax.swing.UIManager#getSystemLookAndFeelClassName() . 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: LnfUtil.java    From keystore-explorer with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Use the appropriate look and feel for the current platform.
 *
 * @return Look and feel class name used
 */
public static String useLnfForPlatform() {
	String lnfClassName = null;

	if (OperatingSystem.isWindows()) {
		lnfClassName = UIManager.getSystemLookAndFeelClassName();
	} else if (OperatingSystem.isMacOs())  {
		if (isVAquaAvailable()){
			lnfClassName = VAQUA_LAF_CLASS;
		} else {
			lnfClassName = UIManager.getSystemLookAndFeelClassName();
		}
	} else {
		String xdgCurrentDesktop = System.getenv("XDG_CURRENT_DESKTOP");
		if ("Unity".equalsIgnoreCase(xdgCurrentDesktop)
				|| "XFCE".equalsIgnoreCase(xdgCurrentDesktop)
				|| "GNOME".equalsIgnoreCase(xdgCurrentDesktop)
				|| "X-Cinnamon".equalsIgnoreCase(xdgCurrentDesktop)
				|| "LXDE".equalsIgnoreCase(xdgCurrentDesktop)
				) {
			lnfClassName = UIManager.getSystemLookAndFeelClassName();
		} else {
			lnfClassName = FlatLightLaf.class.getName();
		}
	}

	useLnf(lnfClassName);

	return lnfClassName;
}
 
Example 2
Source File: MenuItemIconTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    robot = new Robot();
    String name = UIManager.getSystemLookAndFeelClassName();
    try {
        UIManager.setLookAndFeel(name);
    } catch (ClassNotFoundException | InstantiationException |
            IllegalAccessException | UnsupportedLookAndFeelException e) {
        throw new RuntimeException("Test Failed");
    }
    createUI();
    robot.waitForIdle();
    executeTest();
    if (!"".equals(errorMessage)) {
        throw new RuntimeException(errorMessage);
    }
}
 
Example 3
Source File: MenuItemIconTest.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    robot = new Robot();
    String name = UIManager.getSystemLookAndFeelClassName();
    try {
        UIManager.setLookAndFeel(name);
    } catch (ClassNotFoundException | InstantiationException |
            IllegalAccessException | UnsupportedLookAndFeelException e) {
        throw new RuntimeException("Test Failed");
    }
    createUI();
    robot.waitForIdle();
    executeTest();
    if (!"".equals(errorMessage)) {
        throw new RuntimeException(errorMessage);
    }
}
 
Example 4
Source File: Util.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Tries to set default L&F according to platform.
 * Uses:
 *   Metal L&F on Linux and Solaris
 *   Windows L&F on Windows
 *   Aqua L&F on Mac OS X
 *   System L&F on other OS
 */
public static void setDefaultLookAndFeel () {
    String uiClassName;
    if (Utilities.isWindows()) {
        uiClassName = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel"; //NOI18N
    } else if (Utilities.isMac()) {
        uiClassName = "com.apple.laf.AquaLookAndFeel"; //NOI18N
    } else if (Utilities.isUnix()) {
        uiClassName = "javax.swing.plaf.metal.MetalLookAndFeel"; //NOI18N
    } else {
        uiClassName = UIManager.getSystemLookAndFeelClassName();
    }
    if (uiClassName.equals(UIManager.getLookAndFeel().getClass().getName())) {
        //Desired L&F is already set
        return;
    }
    try {
        UIManager.setLookAndFeel(uiClassName);
    } catch (Exception ex) {
        System.err.println("Cannot set L&F " + uiClassName); //NOI18N
        System.err.println("Exception:" + ex.getMessage()); //NOI18N
        ex.printStackTrace();
    }
}
 
Example 5
Source File: MenuItemIconTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    robot = new Robot();
    String name = UIManager.getSystemLookAndFeelClassName();
    try {
        UIManager.setLookAndFeel(name);
    } catch (ClassNotFoundException | InstantiationException |
            IllegalAccessException | UnsupportedLookAndFeelException e) {
        throw new RuntimeException("Test Failed");
    }
    createUI();
    robot.waitForIdle();
    executeTest();
    if (!"".equals(errorMessage)) {
        throw new RuntimeException(errorMessage);
    }
}
 
Example 6
Source File: MenuItemIconTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    robot = new Robot();
    String name = UIManager.getSystemLookAndFeelClassName();
    try {
        UIManager.setLookAndFeel(name);
    } catch (ClassNotFoundException | InstantiationException |
            IllegalAccessException | UnsupportedLookAndFeelException e) {
        throw new RuntimeException("Test Failed");
    }
    createUI();
    robot.waitForIdle();
    executeTest();
    if (!"".equals(errorMessage)) {
        throw new RuntimeException(errorMessage);
    }
}
 
Example 7
Source File: PCGenUIManager.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void initializeGUI()
{
	DesktopHandler.initialize();
	pcgenFrame = new PCGenFrame(new UIContext());
	String className = UIManager.getSystemLookAndFeelClassName();
	try
	{
		UIManager.setLookAndFeel(className);
	} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e)
	{
		Logging.errorPrint("system look and feel not found", e);
	}

}
 
Example 8
Source File: GUI2CommandLine.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
protected void handleOption(String option, String optionExtraPart) {
    if ("-clear".equals(option)) {
        GUISaveState.clear();
        System.exit(0);
    } else if ("-d".equals(option) || "--nodock".equals(option)) {
        // For backwards compatibility, keep parsing the flag
        System.err.println("Flag '" + option + "' is deprecated and will be removed in Spotbugs 4.0.0");
    } else if ("-look".equals(option)) {
        String arg = optionExtraPart;
        String theme = null;

        if ("plastic".equals(arg)) {
            // You can get the Plastic look and feel from jgoodies.com:
            // http://www.jgoodies.com/downloads/libraries.html
            // Just put "plastic.jar" in the lib directory, right next
            // to the other jar files.
            theme = "com.jgoodies.plaf.plastic.PlasticXPLookAndFeel";
        } else if ("gtk".equals(arg)) {
            theme = "com.sun.java.swing.plaf.gtk.GTKLookAndFeel";
        } else if ("native".equals(arg)) {
            theme = UIManager.getSystemLookAndFeelClassName();
        } else {
            System.err.println("Style '" + arg + "' not supported");
        }

        if (theme != null) {
            try {
                UIManager.setLookAndFeel(theme);
            } catch (Exception e) {
                System.err.println("Couldn't load " + arg + " look and feel: " + e.toString());
            }
        }
    } else {
        super.handleOption(option, optionExtraPart);
    }
}
 
Example 9
Source File: PanicDialogPrompt.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * Pass the name of an application as the argument, and this main() method
 * prompts the user with a dialog asking them if they want to abort whatever
 * that application is currently doing.
 * 
 * @param args
 *            the application's arguments. (This is unused.)
 */
public static void main(String[] args) {
	if (args == null || args.length == 0 || args[0].trim().length() == 0)
		args = new String[] { "Unknown" };

	try {
		String lf = UIManager.getSystemLookAndFeelClassName();
		UIManager.setLookAndFeel(lf);
	} catch (Throwable e) {
		e.printStackTrace();
	}

	String name = args[0];
	JButton abortButton = new JButton("Abort");
	abortButton.putClientProperty(DialogFooter.PROPERTY_UNSAFE,
			Boolean.TRUE);
	DialogFooter footer = new DialogFooter(new JComponent[] {},
			new JComponent[] { new JButton("Cancel"), abortButton }, true,
			null);
	int i = QDialog
			.showDialog(new JFrame(),
					"Unresponsive Application", // dialogTitle
					QDialog.getIcon(QDialog.WARNING_MESSAGE), // icon
					QDialog.createContentPanel(
							"The application \""
									+ name
									+ "\" appears to be unresponsive. Would you like to try to abort its current activity?",
							"This may result in data loss, but it may temporarily restore control of the application. If this works, you should immediately try to save your work and exit \""
									+ name + "\".", null, // innerComponent
							true), // selectable
					footer, false, // closeable
					null, // dontShowKey
					null); // alwaysApplyKey
	if (i == 1) {
		System.out.println("abort");
	} else {
		System.out.println("ignore");
	}
	System.exit(0);
}
 
Example 10
Source File: LukeMain.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
  String lookAndFeelClassName = UIManager.getSystemLookAndFeelClassName();
  if (!lookAndFeelClassName.contains("AquaLookAndFeel") && !lookAndFeelClassName.contains("PlasticXPLookAndFeel")) {
    // may be running on linux platform
    lookAndFeelClassName = "javax.swing.plaf.metal.MetalLookAndFeel";
  }
  UIManager.setLookAndFeel(lookAndFeelClassName);

  GraphicsEnvironment genv = GraphicsEnvironment.getLocalGraphicsEnvironment();
  genv.registerFont(FontUtils.createElegantIconFont());

  javax.swing.SwingUtilities.invokeLater(LukeMain::createAndShowGUI);

}
 
Example 11
Source File: UIUtilities.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Set up the user interface.
 */
public static void setupUI() {
    try {
        final String classname = UIManager.getSystemLookAndFeelClassName();
        UIManager.setLookAndFeel(classname);
    }
    catch (Exception e) { 
        e.printStackTrace();
    }

    final UIDefaults defaults = UIManager.getDefaults();

    defaults.put(
        "PopupMenu.border", 
        new BorderUIResource.EtchedBorderUIResource(
            EtchedBorder.RAISED, defaults.getColor("controlShadow"), 
            defaults.getColor("controlLtHighlight")
        )
    );

    final MatteBorder matteborder = new MatteBorder(1, 1, 1, 1, Color.black);
    final EmptyBorder emptyborder = new MatteBorder(2, 2, 2, 2, defaults.getColor("control"));
    final BorderUIResource.CompoundBorderUIResource compBorder
        = new BorderUIResource.CompoundBorderUIResource(emptyborder, matteborder);
    final BorderUIResource.EmptyBorderUIResource emptyBorderUI
        = new BorderUIResource.EmptyBorderUIResource(0, 0, 0, 0);
    defaults.put("SplitPane.border", emptyBorderUI);
    defaults.put("Table.scrollPaneBorder", emptyBorderUI);
    defaults.put("ComboBox.border", compBorder);
    defaults.put("TextField.border", compBorder);
    defaults.put("TextArea.border", compBorder);
    defaults.put("CheckBox.border", compBorder);
    defaults.put("ScrollPane.border", emptyBorderUI);

}
 
Example 12
Source File: PCGenUIManager.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static void initializeGUI()
{
	DesktopHandler.initialize();
	pcgenFrame = new PCGenFrame(new UIContext());
	String className = UIManager.getSystemLookAndFeelClassName();
	try
	{
		UIManager.setLookAndFeel(className);
	} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e)
	{
		Logging.errorPrint("system look and feel not found", e);
	}

}
 
Example 13
Source File: bug6921687.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    if (!Platform.isWindows()) {
        System.out.println("Only Windows platform test. Test is skipped.");
        System.out.println("ok");
        return;
    }
    final String lafClassName = UIManager.getSystemLookAndFeelClassName();
    lafClass  = Class.forName(lafClassName);
    UIManager.setLookAndFeel(lafClassName);
    try {
        SwingUtilities.invokeAndWait(() -> {
            frame = new JFrame();
            frame.setUndecorated(true);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setup(frame);
        });

        final Robot robot = new Robot();
        robot.waitForIdle();
        robot.setAutoDelay(20);
        robot.keyPress(KeyEvent.VK_ALT);
        robot.keyPress(KeyEvent.VK_F);
        robot.keyRelease(KeyEvent.VK_F);
        robot.keyRelease(KeyEvent.VK_ALT);
        robot.waitForIdle();
        checkMnemonics();

        robot.keyPress(KeyEvent.VK_ALT);
        robot.keyPress(KeyEvent.VK_S);
        robot.keyRelease(KeyEvent.VK_S);
        robot.keyRelease(KeyEvent.VK_ALT);
        robot.waitForIdle();
        checkMnemonics();
        System.out.println("ok");
    } finally {
        frame.dispose();
    }

}
 
Example 14
Source File: LocalPreferences.java    From Spark with Apache License 2.0 5 votes vote down vote up
public String getLookAndFeel() {
String defaultstring;
try {
    defaultstring = Spark.isMac() ? Default.getString(Default.DEFAULT_LOOK_AND_FEEL_MAC)
	    : Default.getString(Default.DEFAULT_LOOK_AND_FEEL);
} catch (Exception e) {
    defaultstring = UIManager.getSystemLookAndFeelClassName();
}
if (defaultstring.length() < 1) {
    defaultstring = UIManager.getSystemLookAndFeelClassName();
}
return getString("LookAndFeel", defaultstring);
   }
 
Example 15
Source File: UiUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static String getDefaultLookAndFeelClassName(
        ) {
    switch (UiMode.getCurrentUiMode()) {
        case SWING:
            String className = UIManager.getSystemLookAndFeelClassName();
            
            // if the default look and feel is the cross-platform one, we might
            // need to correct this choice. E.g. - KDE, where GTK look and feel
            // would be much more appropriate
            if (className.equals(UIManager.getCrossPlatformLookAndFeelClassName())) {
                
                // if the current platform is Linux and the desktop manager is
                // KDE, then we should try to use the GTK look and feel
                try {
                    if (System.getProperty("os.name").contains("Linux") &&
                            (System.getenv("KDE_FULL_SESSION") != null)) {
                        // check whether the GTK look and feel class is
                        // available -- we'll get CNFE if it is not and it will
                        // not be set
                        Class.forName(LookAndFeelType.GTK.getClassName());
                        
                        className = LookAndFeelType.GTK.getClassName();
                    }
                } catch (ClassNotFoundException e) {
                    ErrorManager.notifyDebug(ResourceUtils.getString(UiUtils.class,
                            RESOURCE_FAILED_TO_FORCE_GTK), e);
                }
            }
            
            return className;
        default:
            return null;
    }
}
 
Example 16
Source File: LookAndFeel.java    From triplea with GNU General Public License v3.0 5 votes vote down vote up
public static String getDefaultLookAndFeelClassName() {
  return SystemProperties.isMac()
      ? UIManager.getSystemLookAndFeelClassName()
      : getSubstanceLookAndFeelManager()
          .map(SubstanceLookAndFeelManager::getDefaultLookAndFeelClassName)
          .orElseGet(UIManager::getSystemLookAndFeelClassName);
}
 
Example 17
Source File: Envisage.java    From attic-polygene-java with Apache License 2.0 4 votes vote down vote up
private void initLookAndFeel()
{
    String osName = System.getProperty( "os.name" ).toUpperCase();

    // set to use swing anti alias text only for JVM <= 1.5
    System.setProperty( "swing.aatext", "true" );

    // set default swing bold to false, only for JVM 1.5 or above
    UIManager.put( "swing.boldMetal", Boolean.FALSE );

    // set LaF
    LookAndFeel lnf = UIManager.getLookAndFeel();
    if( lnf != null && lnf.getID().equalsIgnoreCase( "Metal" ) )
    {
        final String lnfClassName;
        if( osName.startsWith( "MAC" ) )
        {
            System.setProperty( "com.apple.mrj.application.apple.menu.about.name", "Envisage" ); //TODO i18n
            System.setProperty( "apple.laf.useScreenMenuBar", "true" );
            lnfClassName = UIManager.getSystemLookAndFeelClassName();
        }
        else if( osName.startsWith( "WINDOWS" ) )
        {
            UIManager.put( "ClassLoader", LookUtils.class.getClassLoader() );
            lnfClassName = Options.getSystemLookAndFeelClassName();
            Options.setUseNarrowButtons( false );
        }
        else
        {
            UIManager.put( "ClassLoader", LookUtils.class.getClassLoader() );
            lnfClassName = Options.getCrossPlatformLookAndFeelClassName();
            PlasticLookAndFeel.setTabStyle( PlasticLookAndFeel.TAB_STYLE_METAL_VALUE );
            PlasticLookAndFeel.setPlasticTheme( new ExperienceBlue() );
            Options.setUseNarrowButtons( false );
            //PlasticLookAndFeel.setMyCurrentTheme(new ExperienceBlueDefaultFont());  // for CJK Font
        }

        if( lnfClassName != null )
        {
            try
            {
                UIManager.setLookAndFeel( lnfClassName );
            }
            catch( ClassNotFoundException | IllegalAccessException | InstantiationException |
                   UnsupportedLookAndFeelException ex )
            {
                System.err.println( "Unable to set LookAndFeel, use default LookAndFeel.\n" + ex.getMessage() );
            }
        }
    }
}
 
Example 18
Source File: IdeOptions.java    From CQL with GNU Affero General Public License v3.0 4 votes vote down vote up
private static String defaultLF() {
		return UIManager.getSystemLookAndFeelClassName();
//	    		   System.getProperty("os.name").toLowerCase().contains("mac") 
		// ? UIManager.getSystemLookAndFeelClassName() :
		// "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel";
	}
 
Example 19
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);
  }

}
 
Example 20
Source File: PlatformWindows.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public String getDefaultLFClassName() {
  return UIManager.getSystemLookAndFeelClassName();
}