Search code examples
javaswingjdialogmodality

JDialog with Max/Min Button?


Is there anyway I can add a JPanel in a Modal-less JDialog that also has Max/Min/Close buttons? Even when I do something like this, it does not show max/min button.

JFrame f1 = new JFrame("Book 1 (parent frame)");
            JDialog myDialog = new JDialog(f1);
            myDialog.setVisible(true);

I am looking to have a window like this which is modalless and have max/min buttons

enter image description here

Update: In these examples I can see modalless dialogs with max/min button but can't figure out why are they not working for me


Solution

  • Ok Finally this worked for me. It might be helpful for other readers.

    JFrame.setDefaultLookAndFeelDecorated(true);
                JFrame f = new JFrame();
                f.setResizable(false);
                JPanel p = new JPanel(new GridBagLayout());
                JButton btn = new JButton("Exit");
                p.add(btn,new GridBagConstraints());
                f.getContentPane().add(p);
                f.setSize(400,300);
                f.setLocationRelativeTo(null);
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                f.setVisible(true);
    

    I got impression that I need to put things in JDialog anyway while same could be achieved by using JFrame