Solved

Strange Dialog!

Posted on 2003-12-02
9
330 Views
Last Modified: 2010-03-31
I have created a LoginDialog class(derived from JDialog), LoginDialog have a frame as its member, this frame is the frame of the LoginDialog itself:
public class LoginDialog extends JDialog{
.......
private static JFrame dialogFrame = new JFrame();
static{
      dialogFrame.setSize(231, 199);
      dialogFrame.setVisible(true);
}

and in the constructor of LoginDialog :

public LoginDialog(boolean modal){
      super(dialogFrame, modal);
      setLayout(null);
      ......
      setSize(231, 199);
      pack();
}

and the main() :
public static void main(String args[]) {
     
        LoginDialog ld = new LoginDialog(true);
        ld.show();
    }


When I call the show() method, my dialog is too small, it has the title only! I have to resize it by mouse to see the components in it! It should have the size of 231px in width and 199px in height, I suppose!
AND : There's a another frame with the size of 231px in width and 199px in height!
I think this frame is dialogFrame, but I don't find any reason for it to appear on desktop!
I just want my dialog appear only!
Please help! Thanx
0
Comment
Question by:tinh911
[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
  • 6
  • 3
9 Comments
 
LVL 92

Expert Comment

by:objects
ID: 9864520
> my dialog is too small, it has the title only!

get rid of the pack call, as you are not using a layout manager

>  pack();

> There's a another frame with the size of 231px in width and 199px in height!

you create it, if you don't want it then don't create it, at least don't make it visible.
0
 
LVL 92

Expert Comment

by:objects
ID: 9864555
You also should be setting the layout of the dialogs content pane, and not the dialog directly:

getContentPane().setLayout(null);
0
 
LVL 92

Expert Comment

by:objects
ID: 9864990
if you don't need the frame then create your dialog without an owner.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 3

Expert Comment

by:InNoCenT_Ch1ld
ID: 9865091
>>LoginDialog have a frame as its member

public LoginDialog(boolean modal){
     super(dialogFrame, modal);  
     setLayout(null);
     ......
     setSize(231, 199);
     pack();
}


super(dialogFrame, modal);      <----this line, i afraid is to set the frame as the owner of the JDialog, and not as you have said, the frame IS a member of the dialog.

;)
0
 
LVL 3

Expert Comment

by:InNoCenT_Ch1ld
ID: 9865140
so if you don't want the frame to show up (you dont want a owner frame), you will have to go with objects comment.

-Ch1ld-
0
 
LVL 3

Expert Comment

by:InNoCenT_Ch1ld
ID: 9865150
0
 
LVL 3

Expert Comment

by:InNoCenT_Ch1ld
ID: 9865222
import javax.swing.*

public class MyPanel extends JPanel
{
  public MyPanel()
  {
     setLayout(new FlowLayout());
    JButton button = new JButton("hehe");
    add(button);
  }
}

import javax.swing.*;

public class LoginDialog extends JDialog
{
  MyPanel panel = new MyPanel();

  public LoginDialog(boolean modal){
     super(modal);
     getContentPane().setLayout(new BorderLayout());
     getContentPane().add(panel, BorderLayout.CENTER);
     ......
     setSize(231, 199);
     //pack();
  }
}
0
 
LVL 3

Accepted Solution

by:
InNoCenT_Ch1ld earned 500 total points
ID: 9865232
import javax.swing.*

public class MyPanel extends JPanel
{
  public MyPanel()
  {
     setLayout(new FlowLayout());
    JButton button = new JButton("hehe");
    add(button);
  }
}

import javax.swing.*;

public class LoginDialog extends JDialog
{
  MyPanel panel = new MyPanel();

  public LoginDialog(boolean modal){
     super(modal);
     getContentPane().setLayout(new BorderLayout());
     getContentPane().add(panel, BorderLayout.CENTER);
     ......
     setSize(231, 199);
     //pack();
  }
}

The above example allows you to create your own GUI in MyPanel, then add it to the LoginDialog.
is this what you intended to do?
0
 
LVL 3

Expert Comment

by:InNoCenT_Ch1ld
ID: 9871457
Glad i could help ;)

-Ch1ld-
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
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

630 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