From a291fec94186c761c1508c92ebabd2c338b90941 Mon Sep 17 00:00:00 2001 From: Nico Mexis Date: Wed, 21 Jul 2021 12:26:32 +0200 Subject: [PATCH] Fix newer JDKs --- .../gui/components/BetterJOptionPane.java | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/BetterJOptionPane.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/BetterJOptionPane.java index 9c3dc6ed..a738a224 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/BetterJOptionPane.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/BetterJOptionPane.java @@ -151,8 +151,8 @@ public class BetterJOptionPane //create a new option pane with a empty text and just 'ok' JOptionPane pane = new JOptionPane(""); pane.add(panel, 0); - - JDialog dialog = createNewJDialogue(parentComponent, pane, panel.getName(), 0, (d)-> + + JDialog dialog = createNewJDialogue(parentComponent, pane, panel.getName(), ERROR_MESSAGE, (d)-> { int newHeight = Math.min(minimumHeight, d.getHeight()); d.setMinimumSize(new Dimension(d.getWidth(), newHeight)); @@ -165,28 +165,23 @@ public class BetterJOptionPane private static JDialog createNewJDialogue(Component parentComponent, JOptionPane pane, String title, int style, OnCreate onCreate) { - JDialog dialog = null; - - //reflection to cheat our way around the - // private createDialog(Component parentComponent, String title, int style) - try - { - Method createDialog = pane.getClass().getDeclaredMethod("createDialog", Component.class, String.class, int.class); - createDialog.setAccessible(true); - dialog = (JDialog) createDialog.invoke(pane, parentComponent, title, style); - - //check if the dialogue is in a poor location, attempt to correct - if(dialog.getLocation().getY() == 0 || dialog.getLocation().getY() == 1) - dialog.setLocationRelativeTo(null); //TODO check if BytecodeViewer.viewer is better on multi monitor for this edgecase - else - dialog.setLocationRelativeTo(BytecodeViewer.viewer); - - onCreate.onCreate(dialog); - } - catch(Exception e) - { - e.printStackTrace(); + JDialog dialog = pane.createDialog(parentComponent, title); + if (JDialog.isDefaultLookAndFeelDecorated()) { + boolean supportsWindowDecorations = + UIManager.getLookAndFeel().getSupportsWindowDecorations(); + if (supportsWindowDecorations) { + dialog.setUndecorated(true); + pane.getRootPane().setWindowDecorationStyle(style); + } } + + //check if the dialogue is in a poor location, attempt to correct + if (dialog.getLocation().getY() == 0 || dialog.getLocation().getY() == 1) + dialog.setLocationRelativeTo(null); //TODO check if BytecodeViewer.viewer is better on multi monitor for this edgecase + else + dialog.setLocationRelativeTo(BytecodeViewer.viewer); + + onCreate.onCreate(dialog); dialog.show(); dialog.dispose();