Solved

Strange Dialog!

Posted on 2003-12-02
9
317 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
  • 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
more than one jdk and one jre 1 50
arguments to jar 5 35
going to wrong jsp page 2 34
servlet and mdb, jms error 1 39
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…
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
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.

820 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