• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Dynamic JScrollPane in JPanel

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

I'm looking for a reset size of the scrolling of a Jpanel after resizing.
I do my calculation with the size of labels displayed
The size is just for multiples of two, but not for others.

I don't see how to solve my problem
Here is my code


Thank you very much
 
Rancher
Posts: 3324
32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The paintComponent() method is used for custom painting, not for setting the preferred size of the component. You should definitely not be invoking revalidate() and setPreferredSize() from within that method. In fact there is no reason for you to override the paintComponent() method at all.

You should NOT be using setPreferredSize() anywhere in your code. Setting the preferred size is the job of the layout manager.

If you use an appropriate layout manager the preferred size will be determined for you and scrolling will work properly. Read the Swing tutorial on Layout Managers for more information and examples.
 
Marshal
Posts: 79979
397
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And welcome to the Ranch
 
Frederic Poesson
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Rob Camick wrote:The paintComponent() method is used for custom painting, not for setting the preferred size of the component. You should definitely not be invoking revalidate() and setPreferredSize() from within that method. In fact there is no reason for you to override the paintComponent() method at all.

You should NOT be using setPreferredSize() anywhere in your code. Setting the preferred size is the job of the layout manager.

If you use an appropriate layout manager the preferred size will be determined for you and scrolling will work properly. Read the Swing tutorial on Layout Managers for more information and examples.



Actually my design method is to be the best (I'm newbie in java).
Thank you for the link. I used a JGridLayout GridLayout

Campbell Ritchie wrote:And welcome to the Ranch


Thank you
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Frederic Poesson wrote:I used a JGridLayout


I think you mean GridLayout.
 
Your mother was a hamster and your father was a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic