Search code examples
javaswingjscrollpanejlayeredpanejviewport

How to put a component on top of others?


I have a JScrollPanel that includes a big panel which it's self includes 3 inner panels. i want to put a panel (for example) in a special place so that always could be seen, I mean the user can scroll to anywhere wants but that panel always is in top of the other components and doesn't move. I tried to do that via JLayeredPane but I couldn't. how may I do that?


Solution

  • There's a JLayeredPane example here, but OverlayLayout, seen here, may be of interest. It's not included in the conventional gallery.

    OverlayLayout

    Also consider this example that paints on the scroll pane's JViewport.

    viewport