Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-24-2010, 10:33 PM
Member
 
Join Date: Jan 2010
Posts: 12
Rep Power: 0
ecliptical is on a distinguished road
Question JScrollPane doesn't work?
Hi again,

While writing my GUI I tried to make a JScrollPane by looking through the API. When running my program however it does not work.

Here's the code I used to create a JScrollPane...
Code:
    
    panel5 = new JPanel();
    //Panel for getting info on student
    studentNameLabel2 = new JLabel("Student Info is displayed here");
    studentInfo = new JTextArea();
    studentInfo.setColumns(20);
    studentInfo.setLineWrap(true);
    studentInfo.setRows(5);
    studentInfo.setWrapStyleWord(true);
    studentInfo.setEditable(false);
    studentInfoScroll = new JScrollPane(studentInfo);

    panel5.add(studentNameLabel2);
    panel5.add(studentInfoScroll);
    panel5.add(studentInfo);
Any ideas as to why the JScrollPane isn't showing?

Thanks in advance,
Ecliptical.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 01-24-2010, 11:23 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,452
Rep Power: 8
Fubarable is on a distinguished road
Default
Is the scroll pane's viewport smaller than the JPanel that it holds? Probably not, and if not, no scrollbars will appear.
__________________
When posting code, please use code tags so that your code is readable. To do this, place the tag [code] before your block of code and [/code] after your block of code.
How to use Code Tags
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-24-2010, 11:36 PM
quad64bit's Avatar
Senior Member
 
Join Date: Jul 2009
Location: MD
Posts: 272
Rep Power: 1
quad64bit is on a distinguished road
Default
I suspect that you forgot to add the panel to your gui, or you have a strange layout manager set, or the default layout manager is hiding your panel, or you have a strange size set for the scrollPane, etc. I'd need to see more of the code to be sure - what you have appears to be ok.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-25-2010, 12:52 AM
Member
 
Join Date: Jan 2010
Posts: 12
Rep Power: 0
ecliptical is on a distinguished road
Default
For my GUI driver class, it calls the primary panel which is coded as follows.

Code:
    
    tabbedPanel = new JTabbedPane();
    add(tabbedPanel);
    tabbedPanel.addTab("Add/Remove Student", null, panel1, "Accepts a student into the database");
    tabbedPanel.addTab("Calculate Grades", null, panel4, "Displays the student's grades");
    //tabbedPanel.addTab("Manage Students", null, panel3, "Manages students");
    tabbedPanel.addTab("Student Info", null, panel5, "Gets student Info");
    tabbedPanel.addTab("Add/Remove Teacher", null, panel2, "Hires/Fires a Teacher");
    tabbedPanel.addTab("Teacher Info", null, panel6, "Displays info on Teachers");
    tabbedPanel.addTab("Edit Teachers", null, panel7, "Manages Teachers");
    
    primary = new JPanel();
    primary.setBackground (Color.white);
    primary.setPreferredSize (new Dimension(500, 675));
    primary.setLayout( new BorderLayout() );
    primary.add( tabbedPanel, BorderLayout.CENTER );
Is there any conflict here as to why the scroll bar is not showing?
My GUI consists of JTabbedPanes as well.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-25-2010, 01:35 AM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 6,452
Rep Power: 8
Fubarable is on a distinguished road
Default
Have you tested my suggestion? Have you even read what I wrote? It's a simple matter of calling System.out.println(whatever.getSize()) (but only after the components have been rendered by calling either pack() or setVisible(true) on the JFrame) to see what is the actual size of the component held in the JScrollPane vs the JScrollPane's viewport? Alternatively you could set the preferredSize of the component held by the scrollpane to a large dimension to see if scrollpanes show up.
__________________
When posting code, please use code tags so that your code is readable. To do this, place the tag [code] before your block of code and [/code] after your block of code.
How to use Code Tags
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Tags
jscrollpane, scrollbar

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

BB 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 and jdescktoppane miladirooni New To Java 2 11-03-2009 10:42 AM
[SOLVED] JTextArea with JScrollPane AndrewM16921 AWT / Swing 8 10-30-2009 01:06 AM
jscrollpane kaemonsaionji New To Java 3 02-25-2009 09:39 AM
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


All times are GMT +2. The time now is 08:55 PM.



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