Java:Netbeans 中的 JLayeredPane
我正在使用 netbeans IDE 为 java 程序开发 GUI。我想在我的 GUI 中使用 JLayeredPane。我在 jLayeredPane 的两层上添加了 JPanel(jPanel5) 和 Canvas(canvas),并生成了此代码:
jPanel5.setBounds(0, 0, 749, 549);
jLayeredPane1.add(jPanel5, javax.swing.JLayeredPane.DEFAULT_LAYER);
canvas1.setBounds(0, 0, 40, 30);
jLayeredPane1.add(canvas1, javax.swing.JLayeredPane.DEFAULT_LAYER);
如您所知,此代码无法编辑。我不希望它们位于同一层(DEFAULT_LAYER)。我使用方法 setLayer() 方法如下:
jLayeredPane1.setLayer(canvas1 , 2);
jLayeredPane1.setLayer(jPanel5 , 1);
但我仍然不确定我的目的是否实现。
如何将这两个组件设置在两层上?
谢谢 !
I am using netbeans IDE to develop a GUI for a java program. I want to use a JLayeredPane in my GUI. I added a JPanel(jPanel5) and a Canvas(canvas) on two layers to my jLayeredPane and This code is generated:
jPanel5.setBounds(0, 0, 749, 549);
jLayeredPane1.add(jPanel5, javax.swing.JLayeredPane.DEFAULT_LAYER);
canvas1.setBounds(0, 0, 40, 30);
jLayeredPane1.add(canvas1, javax.swing.JLayeredPane.DEFAULT_LAYER);
As you know, this code can not be edited. I don't want these to be on same layer(DEFAULT_LAYER). I used method setLayer() method as:
jLayeredPane1.setLayer(canvas1 , 2);
jLayeredPane1.setLayer(jPanel5 , 1);
but still I'm not sure that my porpose is achived.
How can I set these tow components on two layers ?
Thank you !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 GUI 编辑器中选择要更改的面板。
然后在“属性”窗口中,向下滚动到“布局”部分。在那里您将找到一个属性“图层”,您可以在其中选择预定义值,或者只需键入所需的图层。
一般来说:“受保护”部分中的代码始终通过组件(或其祖先)的属性进行控制。
Select the panel you want to change in the GUI editor.
Then in the "Properties" Window, scroll down to the "Layout" section. There you'll find a property "Layer" where you can either choose a predefined value, or simply type in the layer you want.
In general: code that is in a "guarded" section is always controlled through the properties of the component (or it's ancestor).