Using a JScrollPane with a JTextArea [duplicate]

岁酱吖の 提交于 2020-01-07 09:50:10

问题


Possible Duplicate:
Java Textarea ScrollPane

I have code for a scrollbar to appear in a textarea but it doesnt really work. Any suggestions?

    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_ALWAYS);
    panel_1.add(textArea);

回答1:


You need to add the JScrollPane to the panel, not the JTextArea. So instead it should be:

panel_1.add(sbrText);


来源:https://stackoverflow.com/questions/9624305/using-a-jscrollpane-with-a-jtextarea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!