• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Adding JScollPane into JPanel

 
Ranch Hand
Posts: 128
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic