我是java新手,所以要温柔。
我正在向 JFrame 添加多个 JPanel,并且希望它们分层,即一个在另一个之上,两者的大小不同。
查询:为什么我必须先在顶部添加我想要的面板?当然,情况会反过来?
frame.add(panel2);
frame.add(panel1);
我本来以为会反过来,但如果我这样做,就行不通了。
最佳答案
参见容器的方法。
/**
* Returns the z-order index of the component inside the container.
* The higher a component is in the z-order hierarchy, the lower
* its index. The component with the lowest z-order index is
* painted last, above all other child components.
*
* @param comp the component being queried
* @return the z-order index of the component; otherwise
* returns -1 if the component is <code>null</code>
* or doesn't belong to the container
* @see #setComponentZOrder(java.awt.Component, int)
* @since 1.5
*/
public int getComponentZOrder(Component comp) {
}
关于java - 在java中分层JPanel?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4477752/