Hello good day.

I have an idea for my program. I have a Table in my display. I want to add a Component to - let's say - the right of my screen. When I click this component it should display to me buttons and other components that I have added to it. I want this component is activiated I want it to display from one side of my Frame as a layer over the Table that I have in my display; much like a docked panel or overlay panel.

I would love to know how I could accomplish this please? Are there any components that would facilitate this?

My current GUI setup is this.

My JFrame has a JScrollPane with a JTabbedPane as it's viewport view. On one of the tabbed pane's JPanel's there is THAT TABLE I mentioned added to it within a JScrollPane.

there are four ways

  • OverLayout or JLayeredPane

  • GlassPane

  • JLayer (required Java7 based on JXLayer - Java6)

  • Java Accordion

_____________________________________________

  • note don't to use JViewport for this job without own custom RepaintManager

+1 for JLayeredPane - it's what it was designed for

Thank you very much. So do I add the layered pane to the tabbed Pane?

Other way round. You add the layered pane to your JFrame, then add everything to the layered pane so you can overlap things as required.

Okay. Here's another question please:

Searching forums it seems that I have to treat the adding of components to the layered pane as if I were creating my own layout...setLocattion...setBounds...
this is me hardcoding locations. Isn't this bad practice? How do I seamlessly take care of resizing of my frame using layered pane please?

Let me be more specific then, whenever I use absolute positioning resizing my JFrame leaves me with some out of place components.

I have added my JLayeredPane to a scroll pane. How do I get my scrollpane to allow scrolling when the JFrame shrinks to a particular dimension please?

whenever I use absolute positioning resizing my JFrame leaves me with some out of place components.

  • add ComponentListener to JFrame,

  • must be delayed by Swing Timer (local variable) with small delay (450-600ms) because this listener firing one event per one pixel, to avoiding (useless) bunch of repainting at runtime

  • call Timer.restart() if resize continued,

  • otherwise Swing Action or ActionListener will fired

  • resize of layer should be wrapped into invokeLater (moving this event to the end of EDT queue)

Thank you all. I decided that I could put my JLayeredPane in a ScrollPane. This worked for me.

I set the size of the layered pane and it's preferred size as well as the size of the scroll pane. Thank you very much for your help. I hope I didn't annoy anyone...(I keep getting this feeling that I am. :s)

Annoying? Absolutely not! Sensible questions, and good use made of the answers. Ideal.
Mark solved?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.