public void showDialog(JComponent dialog) { closeDialog(); JRootPane rootPane = SwingUtilities.getRootPane(mainPanel); if (rootPane == null) { log.severe("could not find root pane for viewer to show dialog " + dialog); } else { JLayeredPane layeredPane = rootPane.getLayeredPane(); Dimension d = dialog.getPreferredSize(); if (dialogPanel == null) { dialogPanel = new DialogPanel(this, new BorderLayout()); } Insets insets = dialogPanel.getInsets(); int width = viewerPanel.getWidth() - insets.left - insets.right; int height = viewerPanel.getHeight() - insets.top - insets.bottom; if (d.width > width) { d.width = width; } if (d.height > height) { d.height = height; } dialogPanel.add(dialog, BorderLayout.CENTER); dialogPanel.setBounds( ((width - d.width) >> 1) + insets.left, ((height - d.height) >> 1) + insets.top, d.width + insets.left + insets.right, d.height + insets.top + insets.bottom); dialog.setVisible(true); layeredPane.add(dialogPanel, DIALOG_LAYER); currentDialog = dialog; mainPanel.repaint(); } }