Win a copy of Pipeline as Code this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

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: 22120
114
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: 22120
114
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: 3232
30
  • 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
 
He got surgery to replace his foot with a pig. He said it was because of this tiny ad:
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic