Solved

JDialog.setMaximized(true)

Posted on 2004-09-02
7
1,757 Views
Last Modified: 2012-05-05
How can I programatically maximize a JDialog? I don't see any setMaximized(true) that I can use.
0
Comment
Question by:r0ckteacher
7 Comments
 
LVL 92

Expert Comment

by:objects
ID: 11968910
not sure if dialogs can be maximised.
0
 
LVL 3

Expert Comment

by:CI-Ia0s
ID: 11969400
Interesting... You can maximize them but you can't minimize them...
0
 
LVL 3

Expert Comment

by:CI-Ia0s
ID: 11969412
I suppose if you could find out the size of the screen you could just set it to be that big... I don't know think there's any kind of "set maximized" property, though. *looks at API again. Not that I can see, at least... Perhaps through a listener... but again, I don't see any way to actually do it...
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 18

Expert Comment

by:armoghan
ID: 11970336
Frame can be iconfied using
frame1.setState(Frame.ICONIFIED);
but could not see anything in JDialog
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 11970514
No, you can not iconise (minimise) a dialog, because it can not have an icon on the task bar below.
Yes, you can maximise a dialog, using the screen size or the (parent) application size.

Simply get that size and setBounds() it.
This question was asked several times before in EE.
;JOOP!
0
 
LVL 37

Accepted Solution

by:
zzynx earned 50 total points
ID: 11970949
/*
 * 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
 
LVL 37

Expert Comment

by:zzynx
ID: 12003766
Thanks for accepting.

PS. Can you tell me what kind of answer would have deserved an A grade in your opinion?
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
printing a file in reverse order is easy in recursion rather than in iteration 3 56
Java Loop 6 59
custom annotations 9 38
Spring Framework HTTPSession management 1 33
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This video teaches viewers about errors in exception handling.

776 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