File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "need showMessageDialog help" Watch "need showMessageDialog help" New topic

need showMessageDialog help

Kimberly Carroll

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?

~ Kim


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);
//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) {

filterPane.add(filterPanel, java.awt.BorderLayout.SOUTH);
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

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:
subject: need showMessageDialog help
It's not a secret anymore!