1
向jtextarea添加「/ n」應該創建一個新行。但在我的情況下,它只是打印出來。我怎樣才能解決這個問題?JTextArea追加新行不起作用
這裏是我的代碼:
package main;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class ConsoleWindow {
static JTextArea out = new JTextArea(5, 50);
final static String newline = "/n";
public static void openWindow(){
JFrame f = new JFrame("Developer console");
JTextField in = new JTextField(50);
JButton b = new JButton("GO");
JPanel p1 = new JPanel(new GridLayout(1,1,10,10));
JPanel p2 = new JPanel(new GridLayout(2,1,10,10));
p1.add(out);
p2.add(in);
p2.add(b);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
printText();
}
});
f.setLayout(new GridLayout(2,1,10,10));
f.add(p1);
f.add(p2);
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
f.setResizable(false);
f.pack();
f.setVisible(true);
}
public static void printText(){
out.append("Hello "+newline);
out.append("Hello123 "+newline);
}
}
更換
笑。這麼小的區別:)謝謝。 –