Skip to content

Instantly share code, notes, and snippets.

@AMDG2
Created March 4, 2016 09:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AMDG2/9c657ed4efe102313831 to your computer and use it in GitHub Desktop.
Save AMDG2/9c657ed4efe102313831 to your computer and use it in GitHub Desktop.
private void initLookAndFeel() {
try {
if (OSValidator.isWindows())
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
else if (OSValidator.isLinux())
UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
else if (OSValidator.isUnix())
UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
else
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | UnsupportedLookAndFeelException | IllegalAccessException e) {
showError(e);
}
}
package hotelManager.utils;
/**
* OSValidator class
*/
public class OSValidator {
private static String OS = System.getProperty("os.name").toLowerCase();
public static boolean isWindows() {
return (OS.contains("win"));
}
public static boolean isMac() {
return (OS.contains("mac"));
}
public static boolean isLinux() {
return OS.contains("linux");
}
public static boolean isUnix() {
return (OS.contains("nix") || OS.contains("nux") || OS.indexOf("aix") > 0);
}
public static boolean isSolaris() {
return (OS.contains("sunos"));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment