It's not a secret anymore!
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JDialog Opens Very Tiny" Watch "JDialog Opens Very Tiny" New topic

JDialog Opens Very Tiny

Anderson Bush

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.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));

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

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

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

/* panel1.add(label1);

okButton.setBounds(new Rectangle(250, 250, 80, 20));
public void actionPerformed(ActionEvent event)
sendPrintRequest = true;

cancelButton.setBounds(new Rectangle(250, 280, 80, 20));
public void actionPerformed(ActionEvent event)
sendPrintRequest = 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);

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:


and call pack() before show().

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.
I agree. Here's the link:
subject: JDialog Opens Very Tiny
It's not a secret anymore!