diff --git a/swing/src/net/sf/openrocket/simulation/extension/impl/JavaCodeConfigurator.java b/swing/src/net/sf/openrocket/simulation/extension/impl/JavaCodeConfigurator.java index ee3e8ca71..ba9fe43b6 100644 --- a/swing/src/net/sf/openrocket/simulation/extension/impl/JavaCodeConfigurator.java +++ b/swing/src/net/sf/openrocket/simulation/extension/impl/JavaCodeConfigurator.java @@ -19,6 +19,7 @@ import net.sf.openrocket.util.Color; public class JavaCodeConfigurator extends AbstractSwingSimulationExtensionConfigurator { private JavaCode extension; private JTextField classNameField; + private StyledLabel errorMsg; private static final Translator trans = Application.getTranslator(); @@ -33,7 +34,7 @@ public class JavaCodeConfigurator extends AbstractSwingSimulationExtensionConfig panel.add(new JLabel(trans.get("SimulationExtension.javacode.className")), "wrap rel"); classNameField = new JTextField(extension.getClassName()); panel.add(classNameField, "growx, wrap"); - StyledLabel errorMsg = new StyledLabel(); + this.errorMsg = new StyledLabel(); errorMsg.setFontColor(Color.DARK_RED.toAWTColor()); errorMsg.setVisible(false); panel.add(errorMsg, "growx, wrap"); @@ -52,26 +53,34 @@ public class JavaCodeConfigurator extends AbstractSwingSimulationExtensionConfig } public void update() { - // Display error message if the class name is invalid - String text = classNameField.getText().trim(); - try { - Class.forName(text); - errorMsg.setVisible(false); - } catch (ClassNotFoundException e) { - // Don't display an error message for an empty field - if (text.length() == 0) { - errorMsg.setVisible(false); - return; - } - errorMsg.setText(trans.get("SimulationExtension.javacode.classnotfound")); - errorMsg.setVisible(true); - } + updateErrorMsg(); } }); + updateErrorMsg(); return panel; } + private void updateErrorMsg() { + if (this.errorMsg == null) { + return; + } + // Display error message if the class name is invalid + String text = classNameField.getText().trim(); + try { + Class.forName(text); + errorMsg.setVisible(false); + } catch (ClassNotFoundException e) { + // Don't display an error message for an empty field + if (text.length() == 0) { + errorMsg.setVisible(false); + return; + } + errorMsg.setText(trans.get("SimulationExtension.javacode.classnotfound")); + errorMsg.setVisible(true); + } + } + @Override protected void close() { if (this.extension != null && this.classNameField != null) {