Simply check their state after the chooser is shown. I.E. Put the line(s) immediately after:
int result = chooser.showOpenDialog(null);
Since the chooser is a modal dialog, those code lines will not be executed until the user dismisses it.
Pregunta
I am adding to JCheckBoxes
to a JFileChooser
to get let the user chose between some extra options when exporting some data to a text file:
JCheckBox field1 = new JCheckBox("Export people gender");
JCheckBox field2 = new JCheckBox("Export people age");
JPanel accessory = new JPanel();
accessory.setLayout(new BoxLayout(accessory, BoxLayout.PAGE_AXIS));
accessory.add(field1);
accessory.add(field2);
JFileChooser chooser = new JFileChooser();
chooser.setAccessory(accessory);
int result = chooser.showOpenDialog(null);
How do I get the 2 extra checkboxes checked/unchecked value (isSelected() true/false) back to the class from which the chooser is called?
Solución
Simply check their state after the chooser is shown. I.E. Put the line(s) immediately after:
int result = chooser.showOpenDialog(null);
Since the chooser is a modal dialog, those code lines will not be executed until the user dismisses it.