Skip to content

Instantly share code, notes, and snippets.

@k33ptoo
Last active October 31, 2019 12:47
Show Gist options
  • Save k33ptoo/2628312c8fdaa91a58a00662adea27b6 to your computer and use it in GitHub Desktop.
Save k33ptoo/2628312c8fdaa91a58a00662adea27b6 to your computer and use it in GitHub Desktop.
Check if User is using another OS switch Java Swing Titlebar
if (OSUtils.getOSType() == OSUtils.OSType.MacOS) {
pnlTop.remove(pnlTitle);
pnlTop.remove(pnlRight);
pnlTop.add(pnlTitle, BorderLayout.EAST);
pnlTop.add(pnlActions, BorderLayout.WEST);
pnlActions.remove(lblClose);
pnlActions.remove(lblMaximize);
pnlActions.remove(lblMinimize);
pnlActions.add(lblClose);
pnlActions.add(lblMaximize);
pnlActions.add(lblMinimize);
pnlTitle.remove(lblTitle);
pnlTitle.setLayout(new FlowLayout(FlowLayout.RIGHT, 10, 8));
pnlTitle.add(lblTitle);
}
if (OSUtils.getOSType() == OSUtils.OSType.Windows) {
pnlTop.remove(pnlTitle);
pnlTop.remove(pnlRight);
pnlTop.add(pnlTitle, BorderLayout.WEST);
pnlTop.add(pnlActions, BorderLayout.EAST);
pnlActions.remove(lblClose);
pnlActions.remove(lblMaximize);
pnlActions.remove(lblMinimize);
pnlActions.add(lblMinimize);
pnlActions.add(lblMaximize);
pnlActions.add(lblClose);
pnlTitle.remove(lblTitle);
pnlTitle.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 8));
pnlTitle.add(lblTitle);
}
// utils
public class OSUtils {
public enum OSType {
Windows, MacOS, Linux
}
private static OSType detectedOS;
public static OSType getOSType() {
if (detectedOS == null) {
String os = System.getProperty("os.name", "generic").toLowerCase(Locale.ENGLISH);
if ((os.contains("mac")) || os.indexOf("darwinf") >= 0) {
detectedOS = OSType.MacOS;
} else {
if (os.contains("win")) {
detectedOS = OSType.Windows;
} else if (os.contains("nux")) {
detectedOS = OSType.Linux;
}
}
}
return detectedOS;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment