Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

need showMessageDialog help

 
Kimberly Carroll
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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));
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic