Problem with JOptionPane and JComboBox....
- From: Dave Reid <ddreid@xxxxxxxxxxx>
- Date: Thu, 13 Jul 2006 18:03:28 +0000 (UTC)
I'm using a ComboBox to change a parameter for an object. When the
selection is made I have an OptionPane come up to make sure the user
really wants to make that change. My problem is that I get 2
OptionPanes that come up.
Here's my definition for the ComboBox:
JComboBox changeFieldStatus = new JComboBox(changeFieldStatusStrings);
changeFieldStatus.setEditable(false);
changeFieldStatus.setSelectedIndex(0);
changeFieldStatus.addItemListener(new FieldStatusHandle
(patientFieldSelect, patientSelectIndex));
And then the ItemListener:
class FieldStatusHandler implements ItemListener
{
PatientRecord[] patientToStatus;
int selectedPat;
FieldStatusHandler(PatientRecord[] patientFieldSelect, int
patientSelectIndex) {
patientToStatus = patientFieldSelect;
selectedPat = patientSelectIndex;
}
public void itemStateChanged(ItemEvent event)
{
int selectedField = 0;
int choice = ((JComboBox)event.getItemSelectable
()).getSelectedIndex();
for (int j = 0; j <= (patientToStatus
[selectedPat].patNumberOfFields - 1); j++)
{
if(patientToStatus[selectedPat].field
[j].fieldSelectedField == true)
{
selectedField = j;
System.out.println("Selected field found at
index " + j);
}
}
if (choice == 0)
{
System.out.println("choice 0");
JOptionPane dialog = new JOptionPane();
int n = dialog.showConfirmDialog( null, "Change" +
patientToStatus[selectedPat].field
[selectedField].fieldName +
" to a Therapy Field?",
"Field Status Change?",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE, null );
if (n == JOptionPane.YES_OPTION)
{
System.out.println("Changing to therapy field");
}
else if (n == JOptionPane.NO_OPTION)
{
System.out.println("Do not change to therapy
field");
}
}
....and then so on through the other options.
I'm guessing that the problem is that this line:
changeFieldStatus.addItemListener(new FieldStatusHandler
(patientFieldSelect, patientSelectIndex));
is looking at both mouse "click" and then "release", which is causing me
to get two of the OptionPanes. But I'm not sure how to fix that.
Any advice?
Thanks in advance...
dave
.
- Follow-Ups:
- Re: Problem with JOptionPane and JComboBox....
- From: andrewthommo
- Re: Problem with JOptionPane and JComboBox....
- Prev by Date: Re: Drawing 25 000 Shape fast
- Next by Date: Re: Auto Select text on textfield focus
- Previous by thread: Drawing 25 000 Shape fast
- Next by thread: Re: Problem with JOptionPane and JComboBox....
- Index(es):