Results 1 to 5 of 5
  1. #1
    ecliptical is offline Member
    Join Date
    Jan 2010
    Posts
    12
    Rep Power
    0

    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...
    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);
    Any ideas as to why the JScrollPane isn't showing?

    Thanks in advance,
    Ecliptical.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Is the scroll pane's viewport smaller than the JPanel that it holds? Probably not, and if not, no scrollbars will appear.

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    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.

  4. #4
    ecliptical is offline Member
    Join Date
    Jan 2010
    Posts
    12
    Rep Power
    0

    Default

    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 );
    Is there any conflict here as to why the scroll bar is not showing?
    My GUI consists of JTabbedPanes as well.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    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.

Similar Threads

  1. jscrollpane and jdescktoppane
    By miladirooni in forum New To Java
    Replies: 2
    Last Post: 11-03-2009, 09:42 AM
  2. JTextArea with JScrollPane
    By AndrewM16921 in forum AWT / Swing
    Replies: 8
    Last Post: 10-30-2009, 12:06 AM
  3. jscrollpane
    By kaemonsaionji in forum New To Java
    Replies: 3
    Last Post: 02-25-2009, 08:39 AM
  4. jscrollpane problem
    By monkey04 in forum AWT / Swing
    Replies: 2
    Last Post: 01-19-2008, 05:23 AM
  5. help with JScrollPane
    By tommy in forum AWT / Swing
    Replies: 1
    Last Post: 08-06-2007, 07:58 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •