Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adding JScollPane into JPanel

 
uttam kumar
Ranch Hand
Posts: 128
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

We have an existing swing application and I have to customize its one of screen. The screen is divided into several parts and each part is being declared as a JPanel. I have to show a file into a particular area which would be scrollable. So now the problem is that I have to add scrolling into the existing JPanel. I tried adding JScrollPane to JPanel but didnt succeed. I read that we have to add JPanel into JScrollPane to achieve the desired result but in my case its not possible. I dont have much idea about swing. Can anyone help me out of this?
Thanks in advance.

Regards,
Uttam Kumar
 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want to add scrolling possibilities to a JPanel you need to add the JPanel to a JScrollPane, not vice versa. The JPanel's preferred size will determine when the scroll bars are needed and how large they will be.
 
uttam kumar
Ranch Hand
Posts: 128
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its not possible in my case. Still I have to achieve the thing. Is there any other way to do it ?
 
Rob Spoor
Sheriff
Pie
Posts: 20526
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why can't you do this? What is preventing you from replacing the JPanel references to JScrollPane references?

Should you really be limited, I see only one option: use another JPanel, add all controls to that instead, add that to the JScrollPane and add the JScrollPane to your JPanel.

So instead of you use this instead: The border layout will ensure that the JScrollPane will fill the entire panel.
 
Rob Camick
Ranch Hand
Posts: 2580
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to customize its one of screen.


Then its possible. If you are changing the code you can do anything you want. If you aren't changing the code then you can't customize it.
 
uttam kumar
Ranch Hand
Posts: 128
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Rob,

Thanks for your quick response.
I was asking the same thing - how to add a JScrollPane to a JPanel.

I will try your suggestion.

Thanks,
Uttam Kumar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic