问题
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