JScrollPanel without scrollbars

Posted by Erik Itland on Stack Overflow See other posts from Stack Overflow or by Erik Itland
Published on 2010-04-15T20:01:01Z Indexed on 2010/04/15 20:03 UTC
Read the original article Hit count: 379

Filed under:
|
|

I'm trying to use a JScrollPanel to display a JPanel that might be too big for the containing Jpanel.

I don't want to show the scrollbars (yes, this is questionable UI design, but it is my best guess of what the customer wants. We use the same idea other places in the application, and I feel this case have given me enough time to ponder if I can do it in a better way, but if you have a better idea I might accept it an answer.)

First attempt: set verticalScrollBarPolicy to NEVER. Result: Scrolling using mouse wheel doesn't work.

Second attempt: set the scrollbars to null. Result: Scrolling using mouse wheel doesn't work.

Third attempt: set scrollbars visible property to false. Result: It is immidiately set visible by Swing.

Fourth attempt: inject a scrollbar where setVisible is overridden to do nothing when called with true. Result: Can't remember exactly, but I think it just didn't work.

Fifth attempt: inject a scrollbar where setBounds are overridden. Result: Just didn't look nice. (I might have missed something here, though.)

Sixth attempt: ask stackoverflow. Result: Pending.

Scrolling works once scrollbars are back.

© Stack Overflow or respective owner

Related posts about java

Related posts about swing