I am fairly new to Java 2, and totally new to JFC/Swing.
I cannot get the JScrollPane to appear. I have consulted
tutorials and samples/demos, and I still can't get it!
All I want is plain scroll bars for plain text - no HTML
or RTF or graphics. Code follows:
Color textBoxForegroundColor = new Color(255, 255, 255);
Color textBoxBackgroundColor = new Color(0, 0, 0);
JTextArea textBox = new JTextArea();
JScrollPane scrollPane = new JScrollPane(textBox,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollPane.setPreferredSize(new Dimension(610, 285));
scrollPane.setVisible(true);
textBox.setForeground(textBoxForegroundColor);
textBox.setBackground(textBoxBackgroundColor);
textBox.setEditable(false);
textBox.setFont(new Font("SansSerif", Font.PLAIN, 14));
textBox.setBounds(8, 90, 610, 285);
textBox.setVisible(true);
mainFrame.getContentPane().add(textBox);
kamesh kompella - 18 Jan 2004 07:02 GMT
mainFrame.getContentPane().add(scrollPane)
^^^^^^^^^^^
Also, you don't need to set your textBox visible. Just don't set it
setVisible(false).
When the JFrame is rendered by way of mainFrame.setVisible(true) it will be
drawn.
HTH
Kamesh
> I am fairly new to Java 2, and totally new to JFC/Swing.
> I cannot get the JScrollPane to appear. I have consulted
[quoted text clipped - 21 lines]
>
> mainFrame.getContentPane().add(textBox);
kamesh kompella - 18 Jan 2004 07:03 GMT
mainFrame.getContentPane().add(scrollPane)
^^^^^^^^^^^
Also, you don't need to set your textBox visible. Just don't set it
setVisible(false).
When the JFrame is rendered by way of mainFrame.setVisible(true) it will be
drawn.
HTH
Kamesh
> I am fairly new to Java 2, and totally new to JFC/Swing.
> I cannot get the JScrollPane to appear. I have consulted
[quoted text clipped - 21 lines]
>
> mainFrame.getContentPane().add(textBox);
kamesh kompella - 18 Jan 2004 07:05 GMT
mainFrame.getContentPane().add(scrollPane)
^^^^^^^^^^^
Also, you don't need to set your textBox visible. Just don't set it
setVisible(false).
When the JFrame is rendered by way of mainFrame.setVisible(true) it will be
drawn.
HTH
Kamesh
> I am fairly new to Java 2, and totally new to JFC/Swing.
> I cannot get the JScrollPane to appear. I have consulted
[quoted text clipped - 21 lines]
>
> mainFrame.getContentPane().add(textBox);
Igor Buzatovic - 19 Jan 2004 10:39 GMT
> I am fairly new to Java 2, and totally new to JFC/Swing.
> I cannot get the JScrollPane to appear. I have consulted
[quoted text clipped - 22 lines]
>
> mainFrame.getContentPane().add(textBox);
instead ofthis line
mainFrame.getContentPane().add(textBox);
you need theese two lines:
mainFrame.getContentPane().add(scrollPane);
scrollPane.getViewport().add(textBox);
Phillip - 19 Jan 2004 16:48 GMT
>>I am fairly new to Java 2, and totally new to JFC/Swing.
>>I cannot get the JScrollPane to appear. I have consulted
[quoted text clipped - 30 lines]
> mainFrame.getContentPane().add(scrollPane);
> scrollPane.getViewport().add(textBox);
Igor,
I finally got the JScrollPane to appear, but it is opaque,
and blocks the 'scrollable document'. I'll try your suggestion.
Thanks.
Phillip