Question

I keep telling myself that this should be simple, and yet I'm completely lost. Let me start by saying that I'm new to NetBeans IDE, and that I am using it out of necessity. I don't really know much about it yet.

I have successfully designed my main window for my application. The right side of the application is essentially a large window into a three-dimensional space that visualizes certain transforms on data sets. I have searched through the palette and the palette manager and even tried to add the Canvas3D component to the palette manually from a JAR, but I still can't get it.

I would really like to be able to drag and drop this component into my application, and intuitively, it seems possible. I'm on Mac OS X; the output from my About NetBeans tells more.

Product Version: NetBeans IDE 6.7 (Build 200906241340)
Java: 1.5.0_19; Java HotSpot(TM) Client VM 1.5.0_19-137
System: Mac OS X version 10.5.7 running on i386; MacRoman; en_US (nb)
Userdir: /Users/dremelofdeath/.netbeans/6.7

Thanks in advance for helping me out -- I really appreciate it.

Was it helpful?

Solution

The Canvas3D is a heavyweight component meaning it uses a native peer component to hook into DirectX or OpenGL so probably this kind of component is not available for drag and drop. Though you could try extending a JPanel.

You can setup the layout manually quite easily using a BoderLayout.

MyFrame extends JFrame {

etc...

 Container container = getContentPane();
 container.setName("main.container");
 container.setLayout(new BorderLayout());

 container.add(new MyCanvasPanel(), BorderLayout.CENTER);

}  

// this could probably be added to the palete
public class MyCanvasPanel extends JPanel {

    SimpleUniverse su;
    Canvas3D canvas3D;

  public MyCanvasPanel() {
        canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
        add("Center", canvas3D);
        su = new SimpleUniverse(canvas3D);
  }

}

OTHER TIPS

Complete beginner guide:

  1. Add a java.awt.Container to the JFrame. (Choose Beans\java.awt.Container). Let the name of that container be canvasContainer.
  2. Add a public variable to the class. (I assume the class name is MyJFrame)

    public Canvas3D canvas3D;

  3. The construction of the frame class is as follows:

    public MyJFrame() {
    initComponents();
    }

    Edit it as follows:

    public MyJFrame() {
    initComponents();
    canvas3D = new Canvas3D(SimpleUniverse.getPreferredConfiguration());
    canvasContainer.add(canvas3D, "Center");
    canvas3D.setSize(canvasContainer.getWidth(), canvasContainer.getHeight());
    }

  4. Add a listener to the Container when it is resized: (Often when the window is resized)
    Choose the container \ Properties \ Events \ componentResized \ canvasContainerComponentResized
    Type the following code:

    if (canvas3D!=null)
    canvas3D.setSize(canvasContainer.getWidth(), canvasContainer.getHeight());

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top