If you create a JScrollPane that has a viewport larger than the JScrollPane\'s component, it displays that component in the upper left.
Is there any way to change this b
Accepting your both comments, but
yes... although I'd really like to arbitrarily position it
there are
important methods to avoiding flickering or jumping on the JViewport
JViewport.setScrollMode(JViewport.BLIT_SCROLL_MODE); JViewport.setScrollMode(JViewport.BACKINGSTORE_SCROLL_MODE); JViewport.setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
and
I don't want to paint to the JViewport, at least not directly -- My real code is a component subclassed from JPanel, as in my example, but it also has other GUI elements in it.
you can use JXLayer (Java6) or parts of methods from JXLayer implemented to the JLayer (Java7) directly
could be too hard, but in all cases you can overlay whatever with JLabel
Notice
all my suggestion to consume MouseEvent by default, J(X)Layer and JLabel with KeyEvents too, but there no issue with redispatch events from ---> to another JComponent
EDIT
wait: no, I don't want to paint the spiral (what you called "snake") in the center of the JScrollPane; I want to paint my component and have my component be displayed in the center of the JScrollPane.
a) JPanel returns Dimension
b) JViewport return Dimension
a) you can centering Dimmension from JPanel (Point) to the center of JViewport (Point)
b) if is there JComponent you can move the JViewport to any getBounds() tha returned JComponent or Point from JPanel inside JScrollPane