0

I have a JFrame generated in my main method which contains a button that opens JDialogs every time it is pressed. The problem I'm having is that the JDialog is not visible in the taskbar, and the solutions I find on internet are when you generate a JDialog in your main.

How can I do to make every new window appear in my Windows taskbar?

For reference, my main looks like that:

public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                Main frame = new Main();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the frame.
 */
public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 450, 300);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    contentPane.setLayout(new BorderLayout(0, 0));
    setContentPane(contentPane);



    JButton btnNouvelleFentre = new JButton("Nouvelle fen\u00EAtre");
    btnNouvelleFentre.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            Chat dlg = new Chat();
        }
    });
    contentPane.add(btnNouvelleFentre, BorderLayout.SOUTH);
}

As you can see, I'm creating an instance of the class Chat, which extends JDialog. A new window is created, but none of them are in the taskbar.

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
zuokuok
  • 323
  • 1
  • 6
  • 16

2 Answers2

2

AFAIK This is the default behaviour for dialogs on Windows and MacOS.

To display another item in the taskbar, you would need to create a new JFrame, this will mean, that if the you were relying on the modal state of the dialog, you will no longer have this functionality.

Having said all that, you should also have a read through The Use of Multiple JFrames, Good/Bad Practice? and consider using a JTabbedPane or CardLayout instead

Community
  • 1
  • 1
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
0

Turns out if you pass a null parent to the JDialog constructor, your dialog will show in the taskbar.

JDialog dialog = new JDialog((Dialog)null);
// so if you say Chat extends JDialog, that would be:
Chat dlg = new Chat((Dialog)null);

(Dialog)null --> cast to java.awt.Dialog

This is an answer from the post: Show JDialog on taskbar It just took me 10 seconds fo find it ;)

Community
  • 1
  • 1
ProgrammingIsAwsome
  • 1,109
  • 7
  • 15