Results 1 to 2 of 2
  1. #1
    ankit1801 is offline Member
    Join Date
    Mar 2011
    Posts
    20
    Rep Power
    0

    Question Problem with adding scroll bar on panel

    i have created a frame in which i have added a JPanel. i need to add scroll bar to this frame. for this i used the following code:
    Java Code:
    JFrame Myframe = new JFrame();
    JPanel p1 = new JPanel();
    Myframe.add(p1);
    Myframe.setSize(900,900);
    Myframe.setVisible(true);
    Myframe.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
    JSrollPane scrollpane = new JScrollpane(p1);
    Myframe.add(scrollpane);
    i am not getting a scrollpane on my panel by using this code. what is the error with it?

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    14,183
    Blog Entries
    7
    Rep Power
    24

    Default

    Don't add your JPanel to the JFrame (you're adding it to a JScrollPane a bit later anyway) and set the preferred size of your JPanel (larger than the size of your JFrame).

    kind regards,

    Jos
    The only person who got everything done by Friday was Robinson Crusoe.

Similar Threads

  1. problem in adding jscrollbar to panel
    By Mani_4 in forum AWT / Swing
    Replies: 6
    Last Post: 06-06-2010, 11:46 AM
  2. Adding a panel to a panel
    By rclausing in forum New To Java
    Replies: 7
    Last Post: 02-02-2010, 06:56 AM
  3. Adding panels into a panel
    By kcakir in forum AWT / Swing
    Replies: 7
    Last Post: 12-07-2009, 06:19 PM
  4. Adding components to a panel
    By jboy in forum New To Java
    Replies: 1
    Last Post: 10-10-2009, 01:02 PM
  5. Replies: 6
    Last Post: 07-28-2008, 06:04 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
  •