且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用JTextArea示例

更新时间:2022-09-21 13:06:55

相对于JLabel显示提示文字,JTextArea有一个先天优势:文字可以拷贝出来。经过下面设置它也能在外观上和JLabel一致。

代码如下:

使用JTextArea示例
JTextArea txtArea=new JTextArea(5,20);// 初始化
// 设置文字
txtArea.setText("We needto update personal business forecast data in staffing plan to get the budgetupdates. Due to the complexities of Staffing Plan sheet, it is necessary tohave one tool, which will help to inject the forecasted data into the staffingplan sheet automatically. The tool will thus, save time of a financial analystto get the budget on time.");
txtArea.setFont(new Font("Arial",Font.PLAIN,14));// 设置字体
txtArea.setLineWrap(true);// 自动换行
txtArea.setWrapStyleWord(true);// 根据单词封装换行字符
txtArea.setBackground(this.getBackground());// 取所在面板的背景色
txtArea.setPreferredSize(new Dimension(800, 30));// 设置宽度
使用JTextArea示例

效果如下:

使用JTextArea示例

注意以上图文无关。






本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/xiandedanteng/p/3698463.html,如需转载请自行联系原作者