I am trying to use a JScrollPanel to display a JPanel, which may be too large for the containing Jpanel.
I don’t want to show scrollbars (yes, this is a dubious user interface design, but this is my best guess about what the client wants. We use the same idea in other places of the application, and I believe that this case gave me enough time to think if I can do it better, but if you have a better idea, I can accept the answer.)
First attempt: set the value of verticalScrollBarPolicy to NEVER. Result: scrolling with the mouse wheel does not work.
Second attempt: set scrollbars to zero. Result: scrolling with the mouse wheel does not work.
Third attempt: set the visible scrollbars property to false. Result: it is explicitly set to visible Swing.
Fourth attempt: enter a scrollbar where setVisible is redefined to do nothing when called with true. Result: I don’t remember exactly, but I think it just didn’t work.
Fifth attempt: enter a scrollbar where setBounds are overridden. Result: It just didn't look pretty. (I could have missed something here).
Sixth attempt: request stackoverflow. Result: This time it worked like a charm.
Scrolling works as soon as the scroll bars return.
source
share