How to convert JTextField
to String and String to JTextField
in Java?
JTextField
allows us to getText()
and setText()
these are used to get and set the contents of the text field, for example.
text = texfield.getText();
hope this helps
how to convert JTextField to string and string to JTextField in java
If you mean how to get and set String from jTextField then you can use following methods:
String str = jTextField.getText() // get string from jtextfield
and
jTextField.setText(str) // set string to jtextfield
//or
new JTextField(str) // set string to jtextfield
You should check JavaDoc for JTextField
// to string
String text = textField.getText();
// to JTextField
textField.setText(text);
You can also create a new text field: new JTextField(text)
Note that this is not conversion. You have two objects, where one has a property of the type of the other one, and you just set/get it.
Reference: javadocs of JTextField
The JTextField
offers a getText()
and a setText()
method - those are for getting and setting the content of the text field.