Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show JDialog on Windows taskbar

I'm trying to display a JDialog in Windows. How do I show a JDialog (like JFrame) on my Windows taskbar?

like image 494
or123456 Avatar asked Nov 04 '11 08:11

or123456


People also ask

How do I open JDialog in center of screen?

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.

Where is JDialog used in an application?

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.

What is Modal JDialog?

JDialog(Dialog owner, String title, boolean modal) Creates a dialog box with the specified Dialog owner, title, and modality.


1 Answers

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);     } } 
like image 157
Ingo Kegel Avatar answered Sep 23 '22 02:09

Ingo Kegel