aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JDialog Opens Very Tiny Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JDialog Opens Very Tiny" Watch "JDialog Opens Very Tiny" New topic
Author

JDialog Opens Very Tiny

Anderson Bush
Greenhorn

Joined: Oct 29, 2002
Posts: 5
The first time this class opens it is only big enough to display the title. But it can be resized and henceforth retains the new size. After reviewing my books, I can't see the problem. I'm a green horn all right, so if you have some tips on what I ought to do to improve this thing, please share...thank you. Code follows...
public class PrintBox extends JDialog
{
JLabel label1 = new JLabel("Please Select Print Options:");
ButtonGroup group1 = new ButtonGroup();
ButtonGroup group2 = new ButtonGroup();
JRadioButton currEntryButton
= new JRadioButton("Print Current Entry Only", true);
JRadioButton allEntryButton
= new JRadioButton("Print Entire Library", false);
JRadioButton printFileButton
= new JRadioButton("Print To File", true);
JRadioButton printScreenButton
= new JRadioButton("Print To Screen", false);
JButton okButton = new JButton("OK");
JButton cancelButton = new JButton("Cancel");
private boolean sendPrintRequest = false;

/** Creates new PrintBox */
public PrintBox(JFrame MainFrame)
{
super(MainFrame, "Print Entries", true);

Container contentPane = getContentPane();
/* JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();*/
contentPane.setLayout(null);
contentPane.setSize(new Dimension(400, 400));

label1.setBounds(new Rectangle(10, 10, 200, 20));
JLabel label2 = new JLabel("Please Select Print Destination:");
label2.setBounds(new Rectangle(10, 120, 200, 20));


currEntryButton.setBounds(new Rectangle(10, 40, 200, 20));
group1.add(currEntryButton);

allEntryButton.setBounds(new Rectangle(10, 70, 200, 20));
group1.add(allEntryButton);

printFileButton.setBounds(new Rectangle(10, 150, 200, 20));
group2.add(printFileButton);

printScreenButton.setBounds(new Rectangle(10, 180, 200, 20));
group2.add(printScreenButton);

/* panel1.add(label1);
panel1.add(currEntryButton);
panel1.add(allEntryButton);
panel1.add(label2);
panel1.add(printFileButton);
panel1.add(printScreenButton);*/

okButton.setBounds(new Rectangle(250, 250, 80, 20));
okButton.addActionListener(new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{
sendPrintRequest = true;
setVisible(false);
}
});

cancelButton.setBounds(new Rectangle(250, 280, 80, 20));
cancelButton.addActionListener(new
ActionListener()
{
public void actionPerformed(ActionEvent event)
{
sendPrintRequest = false;
setVisible(false);
}
});

contentPane.add(label1, null);
contentPane.add(label2, null);
contentPane.add(currEntryButton, null);
contentPane.add(allEntryButton, null);
contentPane.add(printFileButton, null);
contentPane.add(printScreenButton, null);
contentPane.add(okButton, null);
contentPane.add(cancelButton, null);

/* panel2.add(okButton);
panel2.add(cancelButton);

contentPane.add(panel1, BorderLayout.CENTER);
contentPane.add(panel2, BorderLayout.SOUTH);*/

}

public boolean getCurrEntryButtonSelection()
{
return (currEntryButton.isSelected());
}

public boolean getPrintScreenButtonSelection()
{
return printScreenButton.isSelected();
}

public boolean getSendPrintRequest()
{
return sendPrintRequest;
}
}
Bill Liteplo
Ranch Hand

Joined: Oct 16, 2002
Posts: 88
Here's probably the easiest solution:
change

to

and call pack() before show().
e.g.


Frankly, I try to avoid using null layout. It is very messy. Text and other components do not appear the same size on all platforms and L&Fs. It is much cleaner to use real layout managers, so that you don't have to specify sizes nor locations for everything. Your dialog is not so complex that a BorderLayout with a couple BoxLayouts couldn't handle it nicely.
And if your dialog is always going to be the same, why not make it unresizeable (setResizable(false)).
Personally, I have not found a LayoutManager that I like better than OculusLayout. It has never failed to meet all of my layout needs. Granted, I work for the company, but I really do like it.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDialog Opens Very Tiny