How to convert JTextField to String and String to JTextField?

How to convert JTextField to String and String to JTextField in Java?

+6
source share
4 answers

how to convert JTextField to string and string in JTextField in java

If you mean how to get and set String from jTextField, you can use the 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 on JTextField

+13
source
 // to string String text = textField.getText(); // to JTextField textField.setText(text); 

You can also create a new text field: new JTextField(text)

Please note that this is not a conversion. You have two objects that have a property like the other, and you just set / get it.

Link: javadocs JTextField

+6
source

JTextField offers the getText() and setText() methods for getting and setting the contents of a text field.

+4
source

JTextField allows us to getText() and setText() use them to get and set the contents of a text field, for example.

 text = texfield.getText(); 

hope this helps

+3
source

Source: https://habr.com/ru/post/887426/


All Articles