• 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

Scroll Bar Visibility

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having a little problem with ScrollBar visibility. Basically, earlier in the day, the scroll bars were working fine, but now they are not appearing. I had been playing with the paintComponent method of the client of the JScrollPane. The JScrollPane was created without specifying the scrollbar policy, so they were defaulting to AS_NEEDED.

I just wanted to confirm something on a theoretical basis. The client is a instance of a class which extends JPanel, overriding the paintComponent method to do custom painting. (although it does call super.paintComponent at the beginning.)

I do a getSize() on the client and its Dimension is (1000,1000).
I do a getSize() on the client's parent, which is the Viewport, and its size is (187,115).
I do a getSize() on the client's grandparent, which is the JScrollPane, and its size is (190, 118).

The client is clearly larger than either the ViewPort or the ScrollPane. So shouldn't the scrollbars automagically appear?


Thanks in advance for any help.
 
Stephane LeGros
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Btw - I forget to mention that the client was the same size (i.e., 1000x1000) when it was initially added to the ScrollPane, so I don't think the problem is that it was resized and a validate() needs to be done.
 
Stephane LeGros
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have solved the problem.

Basically, at some point I had removed from the panel a setPreferredSize() statement and replaced it with a setSize().

Apparently, when deciding to make scrollbars visible, it looks at the preferred size instead of the actual size.
 
When I was younger I felt like a man trapped inside a woman’s body. Then I was born. My twin is a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic