2

I'm trying to create an app with a JLayeredPane that scales automatically with the size of the parent JFrame (this is the easy part using BorderLayout as layout manager on the frame's content pane). The hard part is the fact that I want the content of the JLayeredPane to automatically resize with the JLayeredPane (and thus the JFrame too).

In fact the functionality I want to achieve is a lot like the dockable console in Netbeans, that just like comes "on top" of the editor when clicked, and when dismissed hides again and docks into the "console" word in the status bar. Obviously I also want resizing behavior to work correctly. What would be the best way to achieve this (if not with JLayeredPane)?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
RDM
  • 4,986
  • 4
  • 34
  • 43
  • Funny that you mention NetBeans. Should you have the option, you can build your application on top of the NetBeans API to have these features ootb. – Foumpie Jul 13 '15 at 14:58

1 Answers1

7

You'll need to use a ComponentListener added to the JLayeredPane and have its content responds to the void componentResized(ComponentEvent e) method.

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • Does this imply the content does not scale dynamically (during resizing) but only when the mouse is released? – RDM Oct 05 '12 at 23:20
  • 1
    No, it means that content will rescale when/if you tell it to and then only when `componentResized(...)` is called. Test it. – Hovercraft Full Of Eels Oct 05 '12 at 23:22
  • @Warkst That's the point of the `JLayered` pane. It has no layout manager to tell the components what to do... – MadProgrammer Oct 05 '12 at 23:27
  • This is working perfectly. @MadProgrammer, I understand the `JLayeredPane` has a `null` layout for a reason, I was just wondering what was the right way to resize the components. Thanks @Hovercraft! – RDM Oct 05 '12 at 23:29