This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JDialog Opens Very Tiny  RSS feed

Anderson Bush
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!