you question is not very clear. the simples way to show the scroll bar is to put your component into
the scrollpane. In your case, you should do:
import javax.swing.*;
import java.awt.*;
public class TestJScroll{
public static void main(String [] args){
JFrame one=new JFrame("滚动条");
one.setSize(800,600);
JTextArea textArea=new JTextArea(6,60);
textArea.setLineWrap(true);
JScrollPane scrollPane=new JScrollPane(textArea);
one.getContentPane().add(scrollPane);
one.setVisible(true);
}
}
the scrollpane. In your case, you should do:
import javax.swing.*;
import java.awt.*;
public class TestJScroll{
public static void main(String [] args){
JFrame one=new JFrame("滚动条");
one.setSize(800,600);
JTextArea textArea=new JTextArea(6,60);
textArea.setLineWrap(true);
JScrollPane scrollPane=new JScrollPane(textArea);
one.getContentPane().add(scrollPane);
one.setVisible(true);
}
}
为什么不把文本区对象textArea加到JFrame类的内容窗格中呢??
即为什么不要one.getContentPane().add(JTextArea);这一句呢??