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("");
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);
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)
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();
}
dialog.show();
dialog.dispose();