Results 1 to 5 of 5
Thread: JScrollPane doesn't work?
- 01-24-2010, 10:33 PM #1
Member
- Join Date
- Jan 2010
- Posts
- 12
- Rep Power
- 0
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...
Java 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);
Thanks in advance,
Ecliptical.
-
Is the scroll pane's viewport smaller than the JPanel that it holds? Probably not, and if not, no scrollbars will appear.
- 01-24-2010, 11:36 PM #3
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.
- 01-25-2010, 12:52 AM #4
Member
- Join Date
- Jan 2010
- Posts
- 12
- Rep Power
- 0
For my GUI driver class, it calls the primary panel which is coded as follows.
Java 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 );
My GUI consists of JTabbedPanes as well.
-
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.
Similar Threads
-
jscrollpane and jdescktoppane
By miladirooni in forum New To JavaReplies: 2Last Post: 11-03-2009, 10:42 AM -
JTextArea with JScrollPane
By AndrewM16921 in forum AWT / SwingReplies: 8Last Post: 10-30-2009, 01:06 AM -
jscrollpane
By kaemonsaionji in forum New To JavaReplies: 3Last Post: 02-25-2009, 09:39 AM -
jscrollpane problem
By monkey04 in forum AWT / SwingReplies: 2Last Post: 01-19-2008, 06:23 AM -
help with JScrollPane
By tommy in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 08:58 PM
Bookmarks