Results 1 to 2 of 2
  1. #1
    Mion is offline Member
    Join Date
    Nov 2011
    Rep Power

    Default multiple JPanels on one Jscrollpane


    How to make add many JPanels of different sizes one below other to one Jscrollpane?

    I tried something like:

    JFrame frame = new JFrame();
    frame.setSize(1200, 900);
    JScrollPane scrollPane = new JScrollPane();
    for (Class nnn:nnns)


    DrawRect drawRect = new DrawRect(nodeList, requests, level); //class that extends JPanel; Preferred size is set dynamically, based on the size of the drawing there


    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);


  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power

    Default Re: multiple JPanels on one Jscrollpane

    You should add a JPanel to the JScrollpane's viewport (not directly to the JScrollPane) to act as a container for the other JPanels. Consider giving this JPanel a BoxLayout so that the other JPanels will be placed one below the other. Most important, read the tutorials on use of scrollpanes and layouts. It will explain all the details.

Similar Threads

  1. Multiple JPanels in Swing?
    By zzuum in forum New To Java
    Replies: 11
    Last Post: 06-02-2011, 03:43 AM
  2. adding multiple jpanels to content pane
    By tooktook22 in forum AWT / Swing
    Replies: 2
    Last Post: 01-19-2011, 07:40 PM
  3. Multiple JPanels within a JFrame
    By horndinkle in forum New To Java
    Replies: 5
    Last Post: 01-09-2011, 08:51 PM
  4. Multiple JPanels Not Working
    By jgezau in forum AWT / Swing
    Replies: 5
    Last Post: 04-17-2009, 05:52 AM
  5. Can't synchronize multiple JPanels in a JFrame
    By vassil_zorev in forum AWT / Swing
    Replies: 0
    Last Post: 12-30-2007, 05:22 PM

Posting Permissions

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