How to convert JTextField to String and String to JTextField?

前端 未结 4 1039
余生分开走
余生分开走 2020-12-20 19:00

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

4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-20 19:35

    // 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

提交回复
热议问题