📄 textareademo.java
字号:
//该示例演示JTextArea和TextArea以及JScrollBar的使用
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class TextAreaDemo extends JFrame implements ActionListener
{
TextArea taLeft;
JTextArea jtaRight;
JScrollPane jspRight;
JButton btnInsert,btnReplace;
JTextField txtContext;
JPanel pnlMain;
public TextAreaDemo()
{
btnInsert=new JButton("插入");
btnInsert.addActionListener(this);
btnReplace=new JButton("替换");
btnReplace.addActionListener(this);
txtContext=new JTextField(10);
taLeft=new TextArea(7,12);
taLeft.setText("这是TextArea");
taLeft.append("\n常用方法演示!");
taLeft.setSelectionStart(2);
taLeft.setSelectionEnd (12);
jtaRight=new JTextArea("这是JTextArea加水平和垂直滚动条",6,12);
jspRight=new JScrollPane(jtaRight);
pnlMain=new JPanel();
pnlMain.add(taLeft);
pnlMain.add(jspRight);
pnlMain.add(txtContext);
pnlMain.add(btnInsert);
pnlMain.add(btnReplace);
this.setContentPane(pnlMain);
setTitle("JTextArea和TextArea示例");
setSize(300,200);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent ae)
{
if (ae.getSource()==btnInsert)
jtaRight.insert(txtContext.getText(),jtaRight.getRows());
if (ae.getSource()==btnReplace){}
}
public static void main(String args[])
{
TextAreaDemo td=new TextAreaDemo();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -