Java:在另一个组件上设置一个组件 [英] Java : set a Component on top of another

查看:461
本文介绍了Java:在另一个组件上设置一个组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Java编写程序.我有一个主JPanel,上面有两个JPanel和一个Canvas.我的目标是在运行程序时调整Canvas的大小.当我最大化画布时,我希望它始终位于其他组件的顶部.
如何为我的Canvas设置此属性?

I am writing a program in java. I have a main JPanel that has two JPanel and one Canvas added on it. I aim to resize the Canvas while running the program. When I maximized the Canvas i want it to be always on top of the other component.
How can I set this property for my Canvas?

推荐答案

您可以将主JPanel替换为JLayeredPanel.分层面板可让您指定某些子组件应位于其他子组件之上.

You could replace your main JPanel with a JLayeredPanel. A layered panel will let you specify that some child components should be layered above other child components.

即:

    JLayeredPane pane = new JLayeredPane();

    JLabel ontop = new JLabel("On top");
    JLabel behind = new JLabel("Behind");

    pane.add(ontop, 2, 0);
    pane.add(behind, 1, 0);

这篇关于Java:在另一个组件上设置一个组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆