Frage

Ok, based on this link JTextField in JDialog retaining value after dispose Im aware now why my TextField is retainning its value, but looking to my code I dont know how to handle this.

enter image description here

My textfield is inside my Main Pane, which is inside a JSplitPane. As left component I have A JTree and as Right Component I have the Main Pane. The SplitPane goes inside the Dialog so, does anyone has a clue how can I handle this? How can I take the value of the TextField after dispose it and open again? I cant simple add the textfield to the dialog, The only way I can see until now is somehow make a vector for the textfields

War es hilfreich?

Lösung

To solve the problem declare the textfield as static:

//JTextField Declaration and Initialization 
static JTextField NODES_TEXT_FIELD = new JTextField();

After that catch the value of the TextField:

int  nodes = Integer.valueOf(NODES_TEXT_FIELD.getText());

In my case was an int value, switch yourself; After that clear the value of the textfield cos it will be stored since the component is static, if you dont do this after dispose the dialog and open again you will see the last value used.

NODES_TEXT_FIELD.setText("");

Special thanks to @kleopatra

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top