Skip to content

Commit dd0d907

Browse files
committed
Better look and feel
1 parent 4454227 commit dd0d907

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

src/main/java/club/bytecode/the/jda/JDA.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import club.bytecode.the.jda.util.GuiUtils;
1515
import club.bytecode.the.jda.util.MiscUtils;
1616
import org.apache.commons.io.FileUtils;
17+
import org.apache.commons.lang3.SystemUtils;
1718
import org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory;
1819
import org.fife.ui.rsyntaxtextarea.TokenMakerFactory;
1920
import org.fife.ui.rsyntaxtextarea.folding.CurlyFoldParser;
@@ -62,15 +63,13 @@ public class JDA {
6263
* @param args files you want to open or CLI
6364
*/
6465
public static void main(String[] args) {
65-
try {
66-
// Fix antialiasing
67-
System.setProperty("awt.useSystemAAFontSettings", "lcd");
68-
System.setProperty("swing.aatext", "true");
66+
// Fix antialiasing
67+
System.setProperty("awt.useSystemAAFontSettings", "lcd");
68+
System.setProperty("swing.aatext", "true");
69+
if (SystemUtils.IS_OS_LINUX) {
6970
GuiUtils.setWmClassName("JDA");
70-
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
71-
} catch (Exception e) {
72-
new ExceptionUI(e);
7371
}
72+
GuiUtils.setLookAndFeel();
7473
try {
7574
System.out.println("JDA (BCV Fork) v" + version);
7675
getJDADirectory();

src/main/java/club/bytecode/the/jda/util/GuiUtils.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77
import java.awt.image.BufferedImage;
88

99
public class GuiUtils {
10-
public static void setWmClassName(String className) throws NoSuchFieldException, IllegalAccessException {
10+
public static void setWmClassName(String className) {
1111
Toolkit xToolkit = Toolkit.getDefaultToolkit();
12-
java.lang.reflect.Field awtAppClassNameField = xToolkit.getClass().getDeclaredField("awtAppClassName");
13-
awtAppClassNameField.setAccessible(true);
14-
awtAppClassNameField.set(xToolkit, className);
12+
java.lang.reflect.Field awtAppClassNameField = null;
13+
try {
14+
awtAppClassNameField = xToolkit.getClass().getDeclaredField("awtAppClassName");
15+
awtAppClassNameField.setAccessible(true);
16+
awtAppClassNameField.set(xToolkit, className);
17+
} catch (Exception e) {
18+
e.printStackTrace();
19+
}
1520
}
1621

1722
public static BufferedImage resize(BufferedImage image, int width, int height) {
@@ -26,4 +31,21 @@ public static ImageIcon resize(Icon icon, int width, int height){
2631
BufferedImage resized = resize(srcImg, width, height);
2732
return new ImageIcon(resized);
2833
}
34+
35+
public static void setLookAndFeel() {
36+
try {
37+
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
38+
if ("Nimbus".equals(info.getName())) {
39+
UIManager.setLookAndFeel(info.getClassName());
40+
break;
41+
}
42+
}
43+
} catch (Exception e) {
44+
try {
45+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
46+
} catch (Exception e1) {
47+
e1.printStackTrace();
48+
}
49+
}
50+
}
2951
}

src/main/java/club/bytecode/the/jda/util/MiscUtils.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package club.bytecode.the.jda.util;
22

3+
import org.apache.commons.lang3.SystemUtils;
4+
35
import java.io.BufferedReader;
46
import java.io.File;
57
import java.io.InputStream;

0 commit comments

Comments
 (0)