views:

77

answers:

1

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: Worked like a charm this time.

Scrolling works once scrollbars are back.

+4  A: 
scrollPane.getVerticalScrollBar().setPreferredSize(new Dimension(0,0));

Will hide the scrollbar, and let you scroll with your mouse wheel.

ring bearer