Results 1 to 9 of 9
Thread: [SOLVED] JScrollPane - HELP!
- 05-10-2008, 01:18 AM #1
Member
- Join Date
- May 2008
- Posts
- 6
- Rep Power
- 0
[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:
If I go past the limits of the JTextArea no scrollbar appears! Any help would be greatly appreciated.Java 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); } }
- 05-10-2008, 02:34 AM #2
What is the purpose of adding textArea to Scrollpane if you just add it directly to JFrame?
remove add(text);freedom exists in the world of ideas
- 05-10-2008, 02:49 AM #3
Member
- Join Date
- May 2008
- Posts
- 6
- Rep Power
- 0
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.
- 05-10-2008, 03:01 AM #4
Ok, you have no containers that holds your component inside the JFrame....
add this to your code,
Replacement for add(text) and add(scroll);Java Code:getContentPane().add(scroll); this.setDefaultCloseOperation(3);
3 means Exit on close.....
getContentPane returns a container that will hold the ScrollPane that holds the textArea.Last edited by sukatoa; 05-10-2008 at 03:09 AM.
freedom exists in the world of ideas
- 05-10-2008, 03:18 AM #5
Member
- Join Date
- May 2008
- Posts
- 6
- Rep Power
- 0
If I replace add(text) and add(scroll) with
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.Java Code:getContentPane().add(scroll); this.setDefaultCloseOperation(3);
- 05-10-2008, 03:47 AM #6
eg.
Java 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); } }freedom exists in the world of ideas
- 05-10-2008, 03:50 AM #7
- 05-10-2008, 03:56 AM #8
Member
- Join Date
- May 2008
- Posts
- 6
- Rep Power
- 0
Ohh thanks. I figured out what i did wrong.
I was setting the bounds of the JTextArea instead of the JScrollPanel, like this:Java Code:text.setBounds(20,20,100,100);
Thanks for your help!Java Code:scroll.setBounds(20,20,100,100);
- 05-10-2008, 03:58 AM #9
Similar Threads
-
JScrollPane with HTML
By Java Tip in forum Java TipReplies: 0Last Post: 03-14-2008, 11:32 AM -
jscrollpane problem
By monkey04 in forum AWT / SwingReplies: 2Last Post: 01-19-2008, 05:23 AM -
help with JScrollPane
By tommy in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 07:58 PM -
how to draw an image inside of jscrollpane
By paty in forum Java AppletsReplies: 1Last Post: 07-24-2007, 12:44 AM -
JScrollPane not scrolling
By Riftwalker in forum Advanced JavaReplies: 2Last Post: 07-17-2007, 08:16 PM


LinkBack URL
About LinkBacks

Bookmarks