From 730abea70bad4124f6f37cf80621b049f5f99b34 Mon Sep 17 00:00:00 2001 From: kruland2607 Date: Wed, 12 Feb 2014 10:31:46 -0600 Subject: [PATCH] Fix problematic bug in motor selection which manifested as: java.lang.IllegalArgumentException: setSelectedIndex: 0 out of bounds at javax.swing.JComboBox.setSelectedIndex(Unknown Source) at net.sf.openrocket.gui.dialogs.motor.thrustcurve.ThrustCurveMotorSelectionPanel.updateData(ThrustCurveMotorSelectionPanel.java:437) The underlying problem was the MotorChooserDialog had been using the GUIUtil.setDisposableDialogOptions call which caused all the underlying models to be cleared when the dialog was closed with the "x" button. This caused the reference to the models in the panel to be disassociated with those in the swing widgets. Since the dialog is reused, this behavior was bad. Changed the dialog so the 'x' button simply hides the dialog and use the GUIUtil.installEscapeCloseOperation to wire in the ESC key. --- .../sf/openrocket/gui/dialogs/motor/MotorChooserDialog.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/swing/src/net/sf/openrocket/gui/dialogs/motor/MotorChooserDialog.java b/swing/src/net/sf/openrocket/gui/dialogs/motor/MotorChooserDialog.java index 5ff870e1b..d7c31c6f7 100644 --- a/swing/src/net/sf/openrocket/gui/dialogs/motor/MotorChooserDialog.java +++ b/swing/src/net/sf/openrocket/gui/dialogs/motor/MotorChooserDialog.java @@ -10,6 +10,7 @@ import javax.swing.JButton; import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JPanel; +import javax.swing.WindowConstants; import net.miginfocom.swing.MigLayout; import net.sf.openrocket.gui.dialogs.motor.thrustcurve.ThrustCurveMotorSelectionPanel; @@ -34,6 +35,8 @@ public class MotorChooserDialog extends JDialog implements CloseableDialog { public MotorChooserDialog(Window owner) { super(owner, trans.get("MotorChooserDialog.title"), Dialog.ModalityType.APPLICATION_MODAL); + // We're going to reuse this dialog so only hide it when it's closed. + this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); JPanel panel = new JPanel(new MigLayout("fill")); @@ -67,7 +70,7 @@ public class MotorChooserDialog extends JDialog implements CloseableDialog { this.setModal(true); this.pack(); this.setLocationByPlatform(true); - GUIUtil.setDisposableDialogOptions(this, okButton); + GUIUtil.installEscapeCloseOperation(this); JComponent focus = selectionPanel.getDefaultFocus(); if (focus != null) {