Solved

Strange Dialog!

Posted on 2003-12-02
9
289 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
Comment Utility
> 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
Comment Utility
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
Comment Utility
if you don't need the frame then create your dialog without an owner.
0
 
LVL 3

Expert Comment

by:InNoCenT_Ch1ld
Comment Utility
>>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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 3

Expert Comment

by:InNoCenT_Ch1ld
Comment Utility
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
Comment Utility
0
 
LVL 3

Expert Comment

by:InNoCenT_Ch1ld
Comment Utility
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
Comment Utility
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
Comment Utility
Glad i could help ;)

-Ch1ld-
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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 will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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:

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now