-1

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.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
theoneiam
  • 11
  • 6
  • Why not use a JMenuBar for your north menu? This will display JMenus and JMenuItems above the south or other components. Otherwise display a pop-up menu to overly the gui with your options (which is what the JMenu does for you) – Hovercraft Full Of Eels Sep 12 '18 at 16:41
  • @HovercraftFullOfEels yea, I know BUT it is not actual menu, therefore I wrote "menu-like": big image-based buttons specially arranged, that's why I did not use JMenu (on the other hand I used JMenu at the top of the main Frame where it has reason for me) – theoneiam Sep 12 '18 at 16:46
  • You still need to pop up your display. You can use a non-decorated dialog, you can use the glass pane or you can use a JLayeredPane, your choice – Hovercraft Full Of Eels Sep 12 '18 at 16:47
  • GlassPane for JPanel? I thought it is only for JFrame? Beside I need that popup would not be movable by mouse - it has to stick right beside the "menu-like-button" it was generated from that is in my NORTH part + I cannot use JLayeredPane inside JTabbedPane, at least that is what i was told... – theoneiam Sep 12 '18 at 16:50
  • You are correct -- a JPanel has no glass pane, but any top-level container with a JRootPane does, such as a JFrame, JDialog and such, and these can be accessable *from the JPanel* by using an appropriate SwingUtilities method. The JFrame actually uses a JLayeredPane type of approach to build its components. You can make components moveable or not. All how you code it. – Hovercraft Full Of Eels Sep 12 '18 at 16:51
  • But if you want a quick detailed high-quality answer, consider posting your [mcve] with your question, giving us something concrete to work with. – Hovercraft Full Of Eels Sep 12 '18 at 16:52
  • But then how can GlassPane it help in my specific case? I need it to be inside JPanel...or do you mean I should make GlassPane in my main JFrame and use that for showing my subemenu-like container? Or even better: could you be some more specific, maybe with some code snippet (like separate answer to my question so in case of success i could make it the right solution)?) – theoneiam Sep 12 '18 at 16:55
  • Again the first code snippets should come from you. Please give us a [mcve] framework with which to help create an answer. This will make answering much easier, and *this* is in your best interests. – Hovercraft Full Of Eels Sep 12 '18 at 16:56
  • Well, unfortunately, as I said several times in some of my other questions to similar questions: I can not do that cos my app is actually one huge collos of code (rendering app) so I would have to provide hundreds of lines of code and still would not be enough as my code does not occur in one specific place/library - it is widely spread across several tens of separate classes etc...sorry :-( – theoneiam Sep 12 '18 at 17:00
  • Please re-read the [mcve](https://stackoverflow.com/help/mcve) link. You should be able to *reproduce* your problem in a new separate program, one that simplifies or *mocks* your other large classes, so that we can compile and run the code ourselves and reproduce the problem. Note that this is something that **we would have to do** if crafting a solution, and all I'm asking is that you do this for us since you are asking volunteers for free help/work, and again, it is far in your best interest to make it easy to help. Myself, I get on here in breaks at work, and so I don't have time to ... – Hovercraft Full Of Eels Sep 12 '18 at 17:03
  • ... create a MCVE for you, but again, I'm not the one asking for help, so it shouldn't be my responsibility. Is an MCVE required? No of course not, and you may get a great answer without one, but if you put in the effort, it may help you get a speedy and better answer. – Hovercraft Full Of Eels Sep 12 '18 at 17:04
  • OK, I have to get back to work, and I do hope you solve your problem. Please comment back if you create your MCVE. If not, I'll check back in about 8 hours to see if you have a solution yet. – Hovercraft Full Of Eels Sep 12 '18 at 17:06
  • As I said in my case it is not possible, sorry, but thank you a lot for your effort trying to help me...actually I am starting to play a bit with your suggestion of GlassPane that would be created after clicking my menu-like image-based button in my NORTH, hope it'll work! – theoneiam Sep 12 '18 at 17:10

1 Answers1

0

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);
theoneiam
  • 11
  • 6