1

I've been staring at Oracle's JLayeredPane tutorials but they are laid out in a manner that is confusing to me and doesn't get at what I am trying to do.

I have an application that up to now has had no concept of layers. Everything is laid out in a single layer, inside a JFrame.

I now want to introduce a component that appears sporadically, as needed, in a certain location, overlaying existing components that stay there normally. Do I have to modify my existing application JFrame so that all its top-level contents (that is, the components that are directly added to the JFrame) are instead added to the JFrame's JLayeredPane?

Or what, exactly?

I'm looking for an easy way to adapt this gui to use layers with the minimum rework of the existing GUI.

Thanks in advance for any help here.

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Steve Cohen
  • 4,679
  • 9
  • 51
  • 89
  • Do you have to display more than one layers at a time. For example a layer is partially covering the layer bellow it? Or only the top level layer will be visible? – Mohayemin Jul 17 '12 at 03:08
  • The main layer will always be visible. One small area of the main layer will occasionally be covered from time to time triggered by events from outside the UI thread. This area is "read-only" - it will never gain keyboard focus and has no need of responding to mouse events. All input will be handled by components in the main layer. A timer-based event will cause it to clear. In other words, it's something like a tool tip except that it's fired by internal events rather than by mouse movement. – Steve Cohen Jul 17 '12 at 12:49

1 Answers1

1

You may want to instead consider drawing your overlay element on the glass pane. That way you can leave the underlying structure completely as-is.

Roddy of the Frozen Peas
  • 14,380
  • 9
  • 49
  • 99
  • That might work, but then I lose the capability of hiding the component by moving it to the back, no? I have to make it invisible, no? There are only a few components that are added directly to the main JFrame's content pane. Could I not simply add them instead to the Layered Pane? Or will that invite more trouble? – Steve Cohen Jul 16 '12 at 21:04
  • No, that won't work - "When the glass pane is visible, it blocks all input events from reaching the components in the content pane" - http://docs.oracle.com/javase/tutorial/uiswing/components/rootpane.html - I want the content pane to be fully functional. – Steve Cohen Jul 16 '12 at 21:09
  • @SteveCohen -- What about the root pane's layered pane, then? Unless your existing GUI specified height, everything should be at the DEFAULT_LAYER. You could stick your overlay elements on the PALETTE_LAYER. – Roddy of the Frozen Peas Jul 16 '12 at 21:14
  • I am with you, I think, but want to ask - what IS the palette layer for? And could I use Integer(50) to place my component on a level that is below the Palette layer but above the default layer? Either way, are you saying that my strategy is simply to add my component to the Palette Layer at this level, and then move it to the back when I want it to disappear? Or should I call setVisible(false)? By the way, this component is for display purposes only - there are no user interactions with it. It will be made to disappear when a timer fires. – Steve Cohen Jul 16 '12 at 21:22