I have been trying to figure this out for a while now but can't quite get it to work. Essentially I have a JavaFX TextArea and I want to construct a new Object named CommandWrapper with the last line of input (ie. line above caret after the ENTER key is pressed). Whenever I hit ENTER after typing a command it works flawlessly but for some reason my String.split() function wont get the empty line if I enter no command ash shown in the GIF below:
Here is the code concerning the issue:
package com.mswordhf.jnet.java.contollers;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.ResourceBundle;
import com.mswordhf.jnet.java.models.JnetModel;
import com.mswordhf.jnet.java.modules.CommandWrapper;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TextArea;
import javafx.scene.input.KeyCode;
public class CmdController implements Initializable {
private JnetModel model;
private int clientIndex;
@FXML private TextArea commandTextArea;
public CmdController(JnetModel model, int clientIndex) {
this.model = model;
this.clientIndex = clientIndex;
}
@Override
public void initialize(URL url, ResourceBundle rb) {
commandTextArea.setOnKeyPressed(keyEvent -> {
if(keyEvent.getCode() == KeyCode.ENTER) {
List<String> lines = Arrays.asList(commandTextArea.getText().split("\\n"));
String command = lines.get(lines.size() - 1);
System.out.println(command);
if(command == "\n") {
System.out.println("Worked");
}else {
CommandWrapper wrapper = new CommandWrapper(command);
model.getClients().get(clientIndex).getHandle().sendModule(wrapper);
if(!model.getCmdOutput.isRunning()) {
model.getCmdOutput.reset();
model.getCmdOutput.start();
}
}
}
});
model.getCmdOutput.setOnSucceeded(event -> {
for(String line : model.getCmdOutput.getValue()) {
commandTextArea.appendText(line + "\n");
}
model.clearList();
});
}
}

==checks for primitive (int,char,double, ...) equality, use.equals(...)to check for object (String,Object, ...) equality. AlsoString#splitdoes not include the regex that the String was split with in the resulting array. Meaning thatif(command.equals("\\n"))will always be false, perhaps you should check for the empty String,if(command.equals("")).