• Post Reply Bookmark Topic Watch Topic
  • New Topic

Not able to add scroll bar for a JPanel.  RSS feed

 
Praveen Kumar Jayaram
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Since JDialog doesn't support setting background color, I am using JPanel over JDialog. I have all set.
Now am planning to using a scroll bar over Jpanel.

I tried this code,
Container c = this.getContentPane();

JScrollPane jsp = new JScrollPane(jPanel1, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
c.add(jsp);

But this is not working. Is it because I am using JPanel over JDialog??
Need some help.

Regards,
Praveen
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Praveen Kumar Jayaram
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks for your reply.

But my problem is in adding scroll bar to JPanel which is placed over a JDialog.

I am new to Java, please help.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Praveen Kumar Jayaram:

But my problem is in adding scroll bar to JPanel which is placed over a JDialog.


You have just been given a ready made solution. Did you even bother to try and run the code? If yes, did you observe the output? If yes did you notice the red and blue background? Did you notice the scroll bars? Is it so complicated that you are unable to comprehend ~22 lines of code?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!