Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Scroll Bar Visibility  RSS feed

 
Stephane LeGros
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!