簡體   English   中英

JTextArea附加新行無效

[英]JTextArea append new line not working

將“/ 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);
}
}

更換

final static String newline = "/n";

通過

final static String newline = "\n";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM