java - 在java中分层JPanel?

标签 java swing

我是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/

相关文章:

java - 在java中平滑地将JButton组件移动到鼠标单击位置

java - org.eclipse.swt.widgets.Table - 添加项目

java - 在 Spring boot 中从 id token 获取主题

java - Java中位数的最大堆和最小堆实现

java - 如何在 KeyListener 中检查 Ctrl 已被释放?

java - SwingWork 链接

java - 挂线程 java.lang.ClassLoader.findBootstrapClass

java - 为什么这个并行梅森素数计算算法会挂起?

java - 如何调试 DO_NOTHING_ON_CLOSE 失败?

Java在滚动条出现时动态改变组件