Answer the question
In order to leave comments, you need to log in
How to overlay jPanel on top of each other, NetBeans?
Hello.
In general, I want to implement something like this: The train of
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
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);
}
}
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 questionAsk a Question
731 491 924 answers to any question