为什么水平滚动条不能与我的JTextArea一起使用?

时间:2019-05-14 21:43:13

标签: java jscrollpane jtextarea

尝试读写文本文档,一切正常,但是水平滚动条不可见。

我尝试手动激活JScrollPane水平滚动条,但这不是结果。

公共类JScrollPaneÜbung扩展了JFrame {

private static final long serialVersionUID = 1L;
private JTextArea area;
private JTextField field;
private JScrollPane scroll;
private JButton dateisuche;
private JButton dateispeichern;
private Panel panel;
private Panel sPanel;


public JScrollPaneÜbung()
{
    area = new JTextArea(32, 41);
    field = new JTextField(30);
    scroll = new JScrollPane(area);
    dateispeichern = new JButton("Speichern");
    dateisuche = new JButton("Durchsuchen");
    panel = new Panel();
    sPanel = new Panel();
    createGUI();
}

 public void createGUI() {
        setBounds(200, 200, 600, 600);
        BorderLayout b = new BorderLayout();
        setLayout(b);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        dateisuche.addActionListener(new JScrollPaneListener(this));
        dateispeichern.addActionListener(new JScrollPaneListener(this));
        panel.add(dateisuche);
        panel.add(field);
        panel.add(scroll);
        sPanel.add(dateispeichern);

        add(panel, BorderLayout.NORTH);
        add(sPanel, BorderLayout.SOUTH);

        setVisible(true);

}
public static void main(String[] args) {
    new JScrollPaneÜbung();
}

看不到水平滚动条,但是我的文本文档比JTextArea长

1 个答案:

答案 0 :(得分:0)

您使用的是常规JPane。请改用JScrollPane。您可以在此处找到指导您的文档。 Resource

相关问题