• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

need showMessageDialog help

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
}
}
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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));
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic