Solved

Strange Dialog!

Posted on 2003-12-02
9
325 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

SharePoint Admin?

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

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ejb entity bean example 2 57
SequenceInputStream example 3 38
Java basic valueOf question 1 50
Using jdbcTemplate.batchUpdate to improve INSERT performance 6 32
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

734 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