滚动条没有出现在框架中,TextArea以某种方式不可编辑,请帮助,谢谢:)
import javax.swing.*;
import java.awt.*;
public class Test extends JFrame{
Container c;
JTextArea jT;
JScrollPane scroll;
public Test(){
c = getContentPane();
c.setLayout(new GridLayout(1,1));
jT = new JTextArea();
scroll = new JScrollPane(); //creating JScrollPane
scroll.add(jT); // adding jT to scroll
c.add(scroll);
}
public static void main(String[] args){
Test fenster = new Test();
fenster.setLocationRelativeTo(null);
fenster.setTitle("Test");
fenster.setSize(200, 200);
fenster.setVisible(true);
fenster.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
答案 0 :(得分:1)
您需要使用需要显示滚动条的组件初始化滚动窗格。
scroll = new JScrollPane(jT); //creating JScrollPane; Do this
// scroll.add(jT); // don't do this