📄 textdemo.java
字号:
//==============================================================
// TextDemo.java - Demonstrate JTextArea
//
// Java学习源代码检索系统 Ver 1.0 20031015 免费正式版
// 版权所有: 中国IT认证实验室(www.ChinaITLab.com)
// 程序制作: ChinaITLab网校教研中心
// 主页地址: www.ChinaITLab.com 中国IT认证实验室
// 论坛地址: bbs.chinaitlab.com
// 电子邮件: Java@ChinaITLab.com
//==============================================================
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class TextDemo extends JFrame {
// Constructor does all the setup work
public TextDemo() {
// Select local system look and feel
try {
UIManager.setLookAndFeel(
UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) { }
// End program when window closes
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
// Use inner panel for a neat appearance
JPanel pane = new JPanel();
// Create text area object
JTextArea theText = new JTextArea();
theText.setFont(new Font("Courier", Font.PLAIN, 12));
theText.setLineWrap(false);
// Add a scroller to the text area object
JScrollPane scroller = new JScrollPane(theText);
scroller.setPreferredSize(new Dimension(300, 150));
scroller.setVerticalScrollBarPolicy(
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
// Create a label for the text area object
String s = "<html>"
+ "<font size=+1><b>Text area:</b></font>"
+ "</html>";
JLabel inputLabel = new JLabel(s);
inputLabel.setLabelFor(theText);
inputLabel.setAlignmentX(Component.LEFT_ALIGNMENT);
// Add all components to the content pane
pane.add(inputLabel);
pane.add(scroller);
getContentPane().add(pane);
setResizable(false);
}
public static void main(String[] args) {
TextDemo app = new TextDemo();
app.setTitle("Text Area Demonstration");
app.setSize(320, 240);
app.show();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -