A
A
Alexander2014-06-25 17:47:18
Java
Alexander, 2014-06-25 17:47:18

How to overlay jPanel on top of each other, NetBeans?

Hello.
In general, I want to implement something like this: The train of
272aca25dd324c198f9c9226bc00f18e.jpg
thought is as follows:
On the left I use jList, and I process the selection from the list, while on the right there are many panels superimposed on each other and, depending on the choice, one of them goes to the foreground. That's just how these panels "overlay", because when added to the frame, they are either nested into each other or moved apart along the frame?
Perhaps there is another solution to this problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2014-06-26
Obiedkov

I figured out the panels, they are superimposed on each other by default, it's just that NetBeans itself pushes them apart, if the sizes are written in the code, then everything is OK, I used jLayeredPane. Now the following question has arisen:
When an element is selected from the list jList at the beginning for all jPane on it layer is set to 0, and for the selected it is set to 1:

private void resetPosition(){
        Component[] panels = jLayeredPane1.getComponents();
        for (Component panel:panels){
                jLayeredPane1.setLayer(panel, 0);
            } 
    }

The panels are swapped, everything is fine, but if there is an enable=true element on the 1st panel and this panel is in the background, then when you hover the mouse over the place where this element is located, it appears on the second panel, when the panels overlap, all elements of the back panels to do enable=false, but for some reason it seems that I got carried away.
Here is an example of how it looks, this is the 1st panel on the front:
this is the 2nd panel immediately when it is selected:
and here is the 2nd panel if you move the mouse over the place of the button and the combo box:
How to solve this problem?

V
Vitaly, 2014-06-28
@silverhawk90

try either to do jlayeredpane.updateUI() every time the layer visibility changes, or use a regular JPanel instead of JLayeredPane, and every time you click on an element in the JList, remove all components from the JPanel, then add all the necessary components and jpanel.updateUI().

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question