Fix newer JDKs

This commit is contained in:
Nico Mexis 2021-07-21 12:26:32 +02:00
parent 0653e8583e
commit a291fec941
No known key found for this signature in database
GPG key ID: 27D6E17CE092AB78

View file

@ -152,7 +152,7 @@ public class BetterJOptionPane
JOptionPane pane = new JOptionPane(""); JOptionPane pane = new JOptionPane("");
pane.add(panel, 0); 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()); int newHeight = Math.min(minimumHeight, d.getHeight());
d.setMinimumSize(new Dimension(d.getWidth(), newHeight)); 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) private static JDialog createNewJDialogue(Component parentComponent, JOptionPane pane, String title, int style, OnCreate onCreate)
{ {
JDialog dialog = null; JDialog dialog = pane.createDialog(parentComponent, title);
if (JDialog.isDefaultLookAndFeelDecorated()) {
//reflection to cheat our way around the boolean supportsWindowDecorations =
// private createDialog(Component parentComponent, String title, int style) UIManager.getLookAndFeel().getSupportsWindowDecorations();
try if (supportsWindowDecorations) {
{ dialog.setUndecorated(true);
Method createDialog = pane.getClass().getDeclaredMethod("createDialog", Component.class, String.class, int.class); pane.getRootPane().setWindowDecorationStyle(style);
createDialog.setAccessible(true); }
dialog = (JDialog) createDialog.invoke(pane, parentComponent, title, style); }
//check if the dialogue is in a poor location, attempt to correct //check if the dialogue is in a poor location, attempt to correct
if(dialog.getLocation().getY() == 0 || dialog.getLocation().getY() == 1) 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 dialog.setLocationRelativeTo(null); //TODO check if BytecodeViewer.viewer is better on multi monitor for this edgecase
else else
dialog.setLocationRelativeTo(BytecodeViewer.viewer); dialog.setLocationRelativeTo(BytecodeViewer.viewer);
onCreate.onCreate(dialog); onCreate.onCreate(dialog);
}
catch(Exception e)
{
e.printStackTrace();
}
dialog.show(); dialog.show();
dialog.dispose(); dialog.dispose();