Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

How to add a maximize button to JDialog

Posted on 2004-10-21
11
Medium Priority
?
5,066 Views
Last Modified: 2008-02-26
How can I add a Maximize button to a JDialog or JOptionPane?
0
Comment
Question by:CharlesSHill
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 12

Expert Comment

by:Giant2
ID: 12378299
using a Frame.
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12378358
You can't maximise a JDialog or JOptionPane.
You can add your own button, but you can only .setSize() to the size from:
          Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
That's all.
;JOOP!
0
 
LVL 37

Accepted Solution

by:
zzynx earned 150 total points
ID: 12378457
Here's some demo code:

/*
 * MaxDialogDemo.java
 *
 */

import java.awt.*;
import javax.swing.*;
/**
 *
 * @author  zzynx
 */
public class MaxDialogDemo extends javax.swing.JPanel {

    JDialog parentDialog = null;
   
    public MaxDialogDemo(JDialog parent) {
        parentDialog = parent;
        initComponents();
    }
   
    private void initComponents() {
        centerPanel = new javax.swing.JPanel();
        southPanel = new javax.swing.JPanel();
        buttonPanel = new javax.swing.JPanel();
        maxButton = new javax.swing.JButton();
        standardButton = new javax.swing.JButton();

        setLayout(new java.awt.BorderLayout());

        add(centerPanel, java.awt.BorderLayout.CENTER);

        maxButton.setText("Maximize");
        maxButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                maxButtonActionPerformed(evt);
            }
        });

        buttonPanel.add(maxButton);

        standardButton.setText("Back to normal");
        standardButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                standardButtonActionPerformed(evt);
            }
        });

        buttonPanel.add(standardButton);

        southPanel.add(buttonPanel);

        add(southPanel, java.awt.BorderLayout.SOUTH);

    }

    private void standardButtonActionPerformed(java.awt.event.ActionEvent evt) {
        parentDialog.hide();
        parentDialog.setSize(600,400);
        parentDialog.setLocationRelativeTo(null);
        parentDialog.show();
    }

    private void maxButtonActionPerformed(java.awt.event.ActionEvent evt) {
        parentDialog.hide();
        parentDialog.setLocation(0,0);
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        parentDialog.setSize(screenSize.width, screenSize.height);
        parentDialog.show();
    }
   
   
    private javax.swing.JPanel buttonPanel;
    private javax.swing.JPanel centerPanel;
    private javax.swing.JButton maxButton;
    private javax.swing.JPanel southPanel;
    private javax.swing.JButton standardButton;
   
    static public void main(String[] args) {
      JFrame x = new JFrame("Maximized Framed");
      x.setLocationRelativeTo(null);
      x.setExtendedState(Frame.MAXIMIZED_BOTH);
      x.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  
      x.setTitle("Maximize Dialog Demo");
      x.setSize(300, 300);
      x.setVisible(true);
     
      JDialog dlg = new JDialog(x, "Demo dialog", true);
      dlg.getContentPane().setLayout(new BorderLayout());
      dlg.getContentPane().add(new MaxDialogDemo(dlg), BorderLayout.CENTER);
      dlg.pack();
     
      dlg.setSize(600,400);
      dlg.setLocationRelativeTo(null); // center
      dlg.show();
    }
}
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 37

Expert Comment

by:zzynx
ID: 12642349
The demo code I posted does exactly what is aked for, so...
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12642376
Although a work-around, zzynx gave a perfect solution.
<*>
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12642396
Thanks sciuriware :)
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12642422
No thanks, I was impressed.
<*>
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12643504
Thank you for accepting Charles.
But, why a B-grade?
0
 

Author Comment

by:CharlesSHill
ID: 12643600
Sorry, the selections said xxx, Good, Excellent, I did not know they were translating to A,B,C. I thought the solution was quite fine so I assigned Good.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12643846
>> I thought the solution was quite fine
You bet ;°)
Just wondered what you expected as an answer that deserves an A grade?

Never mind.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question