Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-10-2008, 02:18 AM
Member
 
Join Date: May 2008
Posts: 6
terox13 is on a distinguished road
[SOLVED] JScrollPane - HELP!
I've spent hours surfing the web trying to get a simple JScrollPane to work.
I've tried many different things but basically this is what I have:

Code:
import javax.swing.*; import java.awt.*; public class Main extends JFrame { JTextArea text; JScrollPane scroll; public Main() { super(""); setLayout(null); setSize(200,200); text = new JTextArea(); text.setBounds(20,20,100,100); scroll = new JScrollPane(text); add(text); add(scroll); } public static void main(String[] args) { JFrame frame = new Main(); frame.setVisible(true); } }
If I go past the limits of the JTextArea no scrollbar appears! Any help would be greatly appreciated.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-10-2008, 03:34 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 509
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
What is the purpose of adding textArea to Scrollpane if you just add it directly to JFrame?

remove add(text);
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 05-10-2008, 03:49 AM
Member
 
Join Date: May 2008
Posts: 6
terox13 is on a distinguished road
I'm not sure I quite understand. If I remove add(text) then the JTextArea won't appear on the JFrame. I am really confused on how to use the scrollbar.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 05-10-2008, 04:01 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 509
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Ok, you have no containers that holds your component inside the JFrame....

add this to your code,
Code:
getContentPane().add(scroll); this.setDefaultCloseOperation(3);
Replacement for add(text) and add(scroll);

3 means Exit on close.....
getContentPane returns a container that will hold the ScrollPane that holds the textArea.
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Last edited by sukatoa : 05-10-2008 at 04:09 AM.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 05-10-2008, 04:18 AM
Member
 
Join Date: May 2008
Posts: 6
terox13 is on a distinguished road
If I replace add(text) and add(scroll) with
Code:
getContentPane().add(scroll); this.setDefaultCloseOperation(3);
the JTextArea doesn't appear in the frame. I just want to have a JTextArea that I can put anywhere inside the frame with a scrollbar. I'm not very familiar with the concepts of constructing a GUI, such as the container. I would appreciate any help such as code on how to do this or a site where I can learn. I've been searching and searching and haven't found one that works for me. Thanks for you're help.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 05-10-2008, 04:47 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 509
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
eg.

Code:
import javax.swing.*; import java.awt.*; public class test extends JFrame { JTextArea text; JScrollPane scroll; public test() { super("TESTING"); setSize(200,200); text = new JTextArea(); scroll = new JScrollPane(text); getContentPane().add(scroll); setDefaultCloseOperation(3); } public static void main(String[] args) { new test().setVisible(true); } }
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 05-10-2008, 04:50 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 509
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
Sun's Java Swing Tutorial.
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #8 (permalink)  
Old 05-10-2008, 04:56 AM
Member
 
Join Date: May 2008
Posts: 6
terox13 is on a distinguished road
Ohh thanks. I figured out what i did wrong.
Code:
text.setBounds(20,20,100,100);
I was setting the bounds of the JTextArea instead of the JScrollPanel, like this:
Code:
scroll.setBounds(20,20,100,100);
Thanks for your help!
Bookmark Post in Technorati
Reply With Quote
  #9 (permalink)  
Old 05-10-2008, 04:58 AM
sukatoa's Avatar
Senior Member
 
Join Date: Jan 2008
Location: Cebu City, Philippines
Posts: 509
sukatoa is on a distinguished road
Send a message via Yahoo to sukatoa
No problem bro....

Just mark this thread as SOLVED...
__________________
A specific, detailed, simple, well elaborated, and "tested before asking" question may gather more quick replies. hopefully
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
JScrollPane with HTML Java Tip Java Tips 0 03-14-2008 12:32 PM
jscrollpane problem monkey04 AWT / Swing 2 01-19-2008 06:23 AM
help with JScrollPane tommy AWT / Swing 1 08-06-2007 08:58 PM
how to draw an image inside of jscrollpane paty Java Applets 1 07-24-2007 01:44 AM
JScrollPane not scrolling Riftwalker Advanced Java 2 07-17-2007 09:16 PM


All times are GMT +3. The time now is 01:06 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org