how to set nextline in textfield


Question

so im creating a chat with a Gui that contains pictures of some men who has a textfield above them that will contain the text that the person chat.

This is by far the hardest project ive created and im quite proud of my accomplisments ive already created a multithreaded server and protocol for my chat client :) ive gotten a guy from Stackoverflow to help me resize my textfield if the text going into it is larger than the size of the textfield :) but now i have another problem when the textfield resizes it resizes only widght because my textfield doesnt change line

ive created the following code to try and make it change lines but it doesnt seem to work could anyone help me?

Send.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {

            String x = textField_chat.getText();
            if (x.length() > 10) {
                String oldLine = x.substring(0,5);

             String newLineString = x.substring(5,x.length());
             txt_ChatPerson1.setText(oldLine+"\n"+newLineString);
            }else {


            textField_chat.setText("");
            txt_ChatPerson1.setVisible(true);
            txt_ChatPerson1.setText(x);
        }
1
1
10/5/2012 4:06:12 PM

Accepted Answer

Use a TextArea instead.

TextArea description from it's javadoc:

Text input component that allows a user to enter multiple lines of plain text. Unlike in previous releases of JavaFX, support for single line input is not available as part of the TextArea control, however this is the sole-purpose of the TextField control. Additionally, if you want a form of rich-text editing, there is also the HTMLEditor control.

1
10/7/2012 6:23:15 AM

I'm taking a shot in the dark here but if you are running this on Windows the new line character is "\r\n".

Try this:

txt_ChatPerson1.setText(oldLine+"\r\n"+newLineString);

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon