Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Strange Dialog!

Posted on 2003-12-02
9
Medium Priority
?
337 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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 1500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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 theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses

876 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