简体   繁体   English

JTextArea到ScrollPane不起作用

[英]JTextArea to ScrollPane not working

The Scrollbar does not appear in the Frame and the TextArea is somehow not editable, please help, thanks :) 滚动条没有出现在“框架”中,并且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);
    }
}

You need initialize the Scroll Pane with the component for which you need to display the scroll bars. 您需要使用需要为其显示滚动条的组件来初始化“滚动窗格”。

    scroll = new JScrollPane(jT);  //creating JScrollPane; Do this
//  scroll.add(jT);                // don't do this

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM