📄 jtextareademo.java
字号:
package components;
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.LineBorder;
public class JTextAreaDemo extends JFrame {
private static final long serialVersionUID = 1L;
public JTextAreaDemo() {
Container container = getContentPane();
container.setLayout(new FlowLayout());
JTextArea[] textAreas = new JTextArea[4];
JScrollPane[] scrollPanes = new JScrollPane[4];
textAreas[0] = new JTextArea();
textAreas[1] = new JTextArea("String");
textAreas[2] = new JTextArea(3,20);
textAreas[3] = new JTextArea("String",3,20);
// # JTextArea methods
// textArea.setLineWrap(true);
// textArea.setWrapStyleWord(false);
// append(String str), insert(String str, int pos)
// textAreas[3].setLineWrap(true);
for (int i = 0; i < textAreas.length; i++) {
textAreas[i].setBorder(LineBorder.createBlackLineBorder());
scrollPanes[i] = new JScrollPane(textAreas[i]);
scrollPanes[i].setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPanes[i].setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
container.add(scrollPanes[i]);
}
textAreas[3].append("append");
textAreas[3].insert("insert", 2);
textAreas[3].setLineWrap(true);
textAreas[3].setWrapStyleWord(true);
setSize(300,300);
setVisible(true);
}
public static void main(String[] args) {
JTextAreaDemo application = new JTextAreaDemo();
application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -