I'm trying to display a JDialog
in Windows. How do I show a JDialog
(like JFrame
) on my Windows taskbar?
If you really want to center a JDialog on screen, you can use code like this: // center a jdialog on screen JDialog d = new JDialog(); d. setSize(400, 300); d. setLocationRelativeTo(null); d.
JDialog is one of the important features of JAVA Swing contributing to interactive desktop-based applications. This is used as a top-level container on which multiple lightweight JAVA swing components can be placed to form a window based application.
JDialog(Dialog owner, String title, boolean modal) Creates a dialog box with the specified Dialog owner, title, and modality.
A dialog itself cannot have a task bar entry, but you can construct a frame that does not have any visible effect and use it as a parent for the dialog. Then it will look like the dialog has a task bar entry. The following code shows you how to do it:
class MyDialog extends JDialog { private static final List<Image> ICONS = Arrays.asList( new ImageIcon("icon_16.png").getImage(), new ImageIcon("icon_32.png").getImage(), new ImageIcon("icon_64.png").getImage()); MyDialog() { super(new DummyFrame("Name on task bar", ICONS)); } public void setVisible(boolean visible) { super.setVisible(visible); if (!visible) { ((DummyFrame)getParent()).dispose(); } } } class DummyFrame extends JFrame { DummyFrame(String title, List<? extends Image> iconImages) { super(title); setUndecorated(true); setVisible(true); setLocationRelativeTo(null); setIconImages(iconImages); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With