Simple JTextArea in JScrollPane problem

Hello everybody,

I think I have a very simple problem, anyway I don't seem to realize what I'm doing wrong.

I want to have a window 400x400 px. Within the complete window there is a scrollable Textarea.

I tried to solve it like this

JFrame frame =new JFrame("ScrollPaneTest");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel panel =new JPanel();

panel.setLayout(new BorderLayout());

JScrollPane scrollPane =new JScrollPane();

JTextArea textArea =new JTextArea();

textArea.setText("Test");

textArea.setBackground(Color.blue);

scrollPane.add(textArea);

scrollPane.validate();

panel.add(scrollPane, BorderLayout.CENTER);

panel.validate();

frame.getContentPane().add(panel);

frame.getContentPane().validate();

frame.setSize(400, 400);

frame.setVisible(true);

I expect to screen to be blue and having test written in it. But it seems like there is nothing in it all.

When I fo frame.pack() the window gets small, just the title bar stays.

Do you know what I'm doing wrong?

Thank you very much,

Stefan

[1414 byte] By [Stefan-Ulma] at [2007-11-27 8:06:49]
# 1
use this constructurepublic JTextArea(int rows, int columns)or set the preferedSize of the textArea or some one else may suggest ...regardsAniruddha
Aniruddha-Herea at 2007-7-12 19:49:28 > top of Java-index,Desktop,Core GUI APIs...
# 2

How about this?

JTextArea textArea = new JTextArea();

textArea.setText("Test");

textArea.setBackground(Color.blue);

JScrollPane scrollPane = new JScrollPane(textArea);

Regards,

Stas

StanislavLa at 2007-7-12 19:49:28 > top of Java-index,Desktop,Core GUI APIs...
# 3
ReplacescrollPane.add(textArea); with scrollPane.setViewportView(textArea);I also think you don't need the validate()-method calls.Nick.
NickDGa at 2007-7-12 19:49:28 > top of Java-index,Desktop,Core GUI APIs...
# 4
Thanks everybody, now its worksMessage was edited by: Stefan-Ulm
Stefan-Ulma at 2007-7-12 19:49:28 > top of Java-index,Desktop,Core GUI APIs...