本文介绍了Java3D与Canvas3D和按钮重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用Java3D对固态物理学进行一些介绍.在深入研究内部的3D事物之后,决定放置一些按钮来测试不同的事物.我的问题出现在这里.

i've been doing some introduction to solidstate physics with using Java3D. After delving into many 3D things inside, decided to put some buttons to test different things. My problem emerged here.

在下面的图片中,我正在使用setLayout(null)放置按钮和Canvas3D:

In the below picture, i was using setLayout(null) to place buttons and Canvas3D:

我在这里不想要的是:

  • Canvas3D与按钮重叠.
  • Canvas3D不会拉伸以保持相同的图片大小/窗口大小比例,因此当我调整窗口大小时,它的大小相同.

然后我尝试对Canvas3D使用setLayout(new BorderLayout());add("Center",component);,而对按钮使用"South","West","East".下图显示了这种情况:

Then i tried using setLayout(new BorderLayout()); and add("Center",component); for the Canvas3D while "South", "West", "East" for the buttons. Below picture is showing the case:

这看起来更好,但是这次又出现了另一个问题:

This looks better but this time another problem comes:

  • 按钮不是我想要的大小(拉伸到窗口),并且不在我想要的偏移位置.
  • 当我将两个放置在同一区域(如南方")时,按钮也会彼此重叠.

问题:如何在按钮刚好位于我想要的位置(x,y)且具有想要的尺寸(h,w)而又不被Canvas3D覆盖的情况下使Canvas3D拉伸到窗口.我为Canvas3D和Buttons->失败尝试了不同的布局.仅显示一种布局.

Question: How can i make Canvas3D stretch to window while buttons are just in place i wanted (x,y) and has the size i wanted (h,w) without being overlapped by Canvas3D. I tried different layouts for Canvas3D and Buttons-->failed. Only one layout is showing.

谢谢您的时间.

Java3D 1.5.2和Eclipse. Windows XP和Intel Centrrino

Java3D 1.5.2 and Eclipse . Windows XP and intel centrino

推荐答案

这实际上不是Java3D问题,而是Swing布局问题.

This isn't really a Java3D problem so much as it is a Swing Layout problem.

正确的解决方案可能是某种嵌套布局,具体取决于您想要的外观.

The correct solution is probably some kind of nested layout, depending on how you want it to look.

例如,您可以尝试使用边框布局,在按钮的北侧或西侧具有嵌套的FlowLayout,该布局可能更接近您要查找的内容.尝试以下类似方法,然后根据需要进行自定义.

For example, you could try a border layout, with a nested FlowLayout on the North or West sides for your buttons, which is probably closer to what you are looking for. Try something like below, and customize to your needs.

JPanel rootPanel = new JPanel(new BorderLayout());
JPanel controlPanel = new JPanel(new FlowLayout());
controlPanel.add(new JButton("Alpha"));
controlPanel.add(new JButton("Beta"));
controlPanel.add(new JButton("Gamma"));
rootPanel.add(controlPanel, BorderLayout.NORTH);
rootPanel.add(myCanvas3D, BorderLayout.CENTER);

这篇关于Java3D与Canvas3D和按钮重叠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-28 05:08