javaswingoverlappingjtabbedpanejlayeredpane

JAVA Can we overlap objects between NORTH and SOUTH in JPanel with BorderLayout?


I have JTabbedPane, one of its tabs contain JPanel with BorderLayout (one JPanel in NORTH for menu-like itmes, quite narrow height of cca. 50px + one JPanel that contians JScrollPane in SOUTH for the content which is quite tall).

When I click on one of the menu-like items in the top NORTH part I want it'd open a submenu-like container/window that would overlap downward above the SOUTH "content" part - can it be done and if so then how to?

Everything I tried still make it cut-out where the SOUTH part starts or it updates the NORTH height which is wrong (that is: not what I want) - the NORTH height have to stay the same.

I was thinking about changing the JPanel to JLayeredPane which would enable me overlaping my objects (JPanels) until I was told one cannot add JLayeredPane into JTabbedPane.

Or should I change my layout from BorderLayout to something else? I was trying set it to null and simply place everything manually but that completely broke the design so I scrapped that immediately right away.


Solution

  • So, after suggestion from @HovercraftFullOfEels (thank you!) to try out GlassPane I play a little bit and this is basically it, just the solution that was in question:

    // MAIN_WINDOW = my main JFrame
    // SUBMENU = my pseudo submenu that overlaps on top of everything else
    // ADDOBJECTS = actual JPanel with submenu-like buttons, positioned manually
    // this is called from a "main" menu-like button
    JPanel SUBMENU = (JPanel) MAIN_WINDOW.getGlassPane();
    SUBMENU.setLayout(null);
    SUBMENU.add(ADDOBJECTS);
    SUBMENU.setVisible(true);