Java Textarea ScrollPane [英] Java Textarea ScrollPane

查看:426
本文介绍了Java Textarea ScrollPane的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个textarea,我需要在必要时将一个滚动条应用于textarea(当文本太长而且无法再读取时)。

I have created a textarea, and i need a scrollbar applied to the textarea when necessary (when the text gets too long down and it cant be read anymore).

这是我写的代码,但由于某种原因,滚动条真的没有出现?

this is the code i have written, but for some reason, the scrollbar doesnt really come up?

    final JTextArea textArea = new JTextArea();
    textArea.setEditable(false);
    textArea.setBounds(10, 152, 456, 255);
    textArea.setBorder(border);
    textArea.setLineWrap(true);
    sbrText = new JScrollPane(textArea);
    sbrText.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
    panel_1.add(textArea);


推荐答案


  • 你由于使用 setBounds(),必须删除使 JTextArea 在屏幕上具有绝对大小的代码行。这使得不可调整大小,而 JScrollPane 仅在其内容可调整大小时才有效。

    • You have to remove the code line that makes the JTextArea have absolute size on the screen due to using setBounds(). This makes it non-resizable, and JScrollPane works only if its content is resizable.

      // wrong
      textArea.setBounds(10, 152, 456, 255);
      


    • 请阅读 JTextArea JScrollPane 教程;请从两个教程中运行示例。

    • Please read JTextArea and JScrollPane tutorial; please run examples from both tutorials.

      这篇关于Java Textarea ScrollPane的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆