Java3D with Canvas3D and button overlapping

懵懂的女人 提交于 2019-12-11 09:34:56

问题


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.

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

What i did not want here is:

  • Canvas3D overlaps buttons.
  • Canvas3D does not stretch to keep same ratio of picture size / window size so when i resize window it just is in same size.

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:

  • Buttons are not the size i wanted(stretches to window) and is not at the offset position i wanted.
  • Buttons also overlap eachother when i put two on the same area like "South".

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.

Thank you for your time.

Java3D 1.5.2 and Eclipse . Windows XP and intel centrino


回答1:


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.

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);


来源:https://stackoverflow.com/questions/12314324/java3d-with-canvas3d-and-button-overlapping

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!