Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDialog Opens Very Tiny

 
Anderson Bush
Greenhorn
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.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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic