当前位置: 技术问答>java相关
JTextArea控件如何设置滚动条啊,TextArea控件都有,怎么新的Swing里更没有了呢?
来源: 互联网 发布时间:2017-03-29
本文导语: JTextArea控件如何设置滚动条啊,TextArea控件都有,怎么新的Swing里更没有了呢? | //try this, you will get a basic idea about this topic //good luck import java.awt.*; import java.awt.event.*; import javax.swing.*...
JTextArea控件如何设置滚动条啊,TextArea控件都有,怎么新的Swing里更没有了呢?
|
//try this, you will get a basic idea about this topic
//good luck
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JTextFrameClass extends JFrame {
private JPanel contentPane;
private BorderLayout borderLayout1 = new BorderLayout();
private JScrollPane jScrollPane1 = new JScrollPane();
private JTextArea jTextArea1 = new JTextArea();
//Construct the frame
public JTextFrameClass() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
contentPane.setToolTipText("");
jTextArea1.setBackground(Color.pink);
jTextArea1.setText("jTextArea1,Pleae continue type untill the vertical scroll bar becomes active!!!"+
"jTextArea1,Pleae continue type untill the vertical scroll bar becomes active!!!"+
"jTextArea1,Pleae continue type untill the vertical scroll bar becomes active!!!"+
"jTextArea1,Pleae continue type untill the vertical scroll bar becomes active!!!");
jTextArea1.setLineWrap(true);
jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
contentPane.add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(jTextArea1, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
public static void main (String args[])
{
JTextFrameClass test = new JTextFrameClass();
test.setSize(200,150) ;
test.show();
}
}
//good luck
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class JTextFrameClass extends JFrame {
private JPanel contentPane;
private BorderLayout borderLayout1 = new BorderLayout();
private JScrollPane jScrollPane1 = new JScrollPane();
private JTextArea jTextArea1 = new JTextArea();
//Construct the frame
public JTextFrameClass() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(borderLayout1);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
contentPane.setToolTipText("");
jTextArea1.setBackground(Color.pink);
jTextArea1.setText("jTextArea1,Pleae continue type untill the vertical scroll bar becomes active!!!"+
"jTextArea1,Pleae continue type untill the vertical scroll bar becomes active!!!"+
"jTextArea1,Pleae continue type untill the vertical scroll bar becomes active!!!"+
"jTextArea1,Pleae continue type untill the vertical scroll bar becomes active!!!");
jTextArea1.setLineWrap(true);
jScrollPane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
jScrollPane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
contentPane.add(jScrollPane1, BorderLayout.CENTER);
jScrollPane1.getViewport().add(jTextArea1, null);
}
//Overridden so we can exit when window is closed
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
public static void main (String args[])
{
JTextFrameClass test = new JTextFrameClass();
test.setSize(200,150) ;
test.show();
}
}