Win a copy of Spring Boot in Practice this week in the Spring 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

JPanel

 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This has got to be easy, but I'm not getting it.
I am displaying a JTable in a JPanel. I am setting the size of the JTable using:
setPreferredScrollableViewportSize( new Dimension( 685, 180 ) )
...but what I'd really like is to have it sized to fit the display area of the JPanel. How do I get that Dimension?
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Peter,
Use the JPanel layout to perform it for you. If you set the JPanel layout to BorderLayout you can add your JTable to the CENTER (default if not specified) then it will work for you.

That way your table will be the size of the panel!
Regards,
Manfred.
 
Peter Lyons
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Manfred!
That works.
Do you have an idea how to do the same thing when I'm placing a JPanel in a tab on a JTabbedPane? It doesn't look like a layout manager can be used for that.
Thanks again...
Peter
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Think panels within panels
 
Peter Lyons
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks to both of you, Mike and Manfred...
I appreciate the help!
Peter <--- trying to think like a JPanel
 
reply
    Bookmark Topic Watch Topic
  • New Topic