Java Swing JTextArea not working

前端 未结 2 1451
后悔当初
后悔当初 2021-01-29 09:18

I\'m working on a game. In this part, a new window opens up to show the game instructions. The only problem is that the JTextArea only shows one line of the .txt file, when ther

2条回答
  •  面向向阳花
    2021-01-29 09:49

    You are reading only one line from a file. Try using this instead to load entire file.

    List lines;
    try {
        lines = Files.readAllLines();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    
    StringBuilder text = new StringBuilder();
    for (String line : lines) {
        text.append(line);
    }
    
    read = new JTextArea(text.toString());
    

提交回复
热议问题