Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / January 2004

Tip: Looking for answers? Try searching our database.

JScrollPane question

Thread view: 
Phillip - 18 Jan 2004 04:13 GMT
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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.