Java3D with Canvas3D with Button Overlap

I was doing an introduction to solid state physics using Java3D. After immersing myself in many 3D things inside, I decided to put some buttons to test different things. My problem arose here.

In the following figure, I used setLayout (null) to place the buttons and Canvas3D:

enter image description here

What I do not need here:

  • The Canvas3D buttons overlap.
  • Canvas3D does not stretch to maintain the same window size / size ratio, so when I resize the window, it just has the same size.

Then I tried to use setLayout(new BorderLayout()); and add("Center",component); for Canvas3D, and for the buttons - "South", "West", "East". The image below is shown:

enter image description here

This looks better, but this time there is another problem:

  • The buttons do not fit the size (stretches to the window) and are not in the offset position that I wanted.
  • The buttons also overlap when I put two in the same area as South.

Question: How to make Canvas3D stretch to the window while the buttons are in the place that I wanted (x, y) and had the size that I wanted (h, w) without overlapping Canvas3D. I tried different layouts for Canvas3D and Buttons -> failed. Only one layout is shown.

Thank you for your time.

Java3D 1.5.2 and Eclipse. Windows XP and Intel centrino

+1
source share
1 answer

This is not a Java3D problem, as it is a Swing Layout problem.

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

For example, you can try a border layout with a nested FlowLayout on the north or west side for your buttons, which is probably closer to what you are looking for. Try something like below and customize according 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); 
+1
source

Source: https://habr.com/ru/post/1432889/


All Articles