File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes need showMessageDialog help 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 "need showMessageDialog help" Watch "need showMessageDialog help" New topic
Author

need showMessageDialog help

Kimberly Carroll
Greenhorn

Joined: Nov 16, 2005
Posts: 1
Hi -

I am having a message dialog show a list of checkboxes. The problem I'm having is that the checkboxes never show up. I put a dialog in a for loop and each checkbox shows up on a new dialog (this is the behavior I was looking for), but I want each checkbox to show up on one panel. My code is below. Can someone please help me get all checkboxes (there's 6 of them) on the panel?

Thanks,
~ Kim

Code:

private class EditViewFilter extends javax.swing.JDialog {
public EditViewFilter(ArrayList items) {
super(new cvtsc.util.editor.EditorFrame(null), "View Options Filter", true);
java.awt.Container filterPane = getContentPane();
javax.swing.JPanel panel = new javax.swing.JPanel(new java.awt.BorderLayout());

/* add checkboxes to panel */
// items are the checkboxes on the dialog
for (int i = 0; i < items.size(); i++) {
javax.swing.JCheckBox checkbox = new javax.swing.JCheckBox(items.get(i).toString(), true);
panel.add(checkbox);
//javax.swing.JOptionPane.showMessageDialog(null, checkbox);
}

filterPane.add(panel, java.awt.BorderLayout.CENTER);

javax.swing.JPanel filterPanel = new javax.swing.JPanel();
javax.swing.JButton ok = new javax.swing.JButton("OK");

ok.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
setVisible(false);
}
});

filterPanel.add(ok);
filterPane.add(filterPanel, java.awt.BorderLayout.SOUTH);
setContentPane(filterPane);
pack();
}
}
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
your problem is this line
javax.swing.JPanel panel = new javax.swing.JPanel(new java.awt.BorderLayout());
combined with
panel.add(checkbox);

this adds the checkbox to the default (BorderLayout.CENTER).
as you can only add one component to the center, each of the
previously added checkboxes are replaced, and the last one added remains

one of the ways to fix - change to a gridlayout
javax.swing.JPanel panel = new javax.swing.JPanel(new java.awt.GridLayout(items.size(),1));
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: need showMessageDialog help