I'm running in to a small snag here...I was trying to create a scrollable text area, and I've implemented it using the following code snippet, which I'm fairly sure is okay. I'd appreciate if you could tell me what's wrong with it?
JTextArea textArea = new JTextArea();
textArea.setBackground(Color.WHITE);
textArea.setPreferredSize(new Dimension(600, 200));
textArea.setWrapStyleWord(true);
textArea.setLineWrap(true);
JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
String s = "";
for (int i = 0; i < 100; i++) {
s += "asdflkjas;ldfkjas;lflsdkjfads;kfja;sdlfafsdf\n";
}
textArea.setText(s);
// method to add Component to a JPanel with GridBagLayout
addComponent(scrollPane, 3, 0, 2, 2);
The problem is simple - everything works fine - the text appears normally, the scroll bars appear okay, the text is wrapped...but I couldn't scroll!
A few pointers, please?
Thanks!! Baggio