[vtkusers] Embedding a vtkRendererWindow in a Java frame/panel

Sebastien Jourdain sebastien.jourdain at kitware.com
Fri Aug 6 19:06:52 EDT 2010


This should do the trick.

import java.awt.BorderLayout;
import javax.swing.JFrame;
import vtk.vtkActor;
import vtk.vtkConeSource;
import vtk.vtkPanel;
import vtk.vtkPolyDataMapper;

public class VTKSample {

public static void main(String[] args) {
// Build the VTK 3D view
// (Should be done before using any vtk
// object or load the native
// library first)
vtkPanel panel3D = new vtkPanel();

// Build a simple VTK pipeline
vtkConeSource coneSource = new vtkConeSource(); coneSource.SetRadius(2);
coneSource.SetAngle(15);
coneSource.SetHeight(2);
coneSource.SetResolution(10);

vtkPolyDataMapper coneMapper = new vtkPolyDataMapper();
coneMapper.SetInput(coneSource.GetOutput());

vtkActor coneActor = new vtkActor();
coneActor.SetMapper(coneMapper);

// Add actor in 3D Panel
panel3D.GetRenderer().AddActor(coneActor);

// Build Java Frame and include the VTK view
JFrame frame = new JFrame("VTK Java Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(panel3D, BorderLayout.CENTER);
frame.setSize(500, 500);
frame.setLocationRelativeTo(null); // Center on desktop frame.setVisible(true);
}
}

Seb

On Fri, Aug 6, 2010 at 6:46 PM, Ambar C <ambarc at gmail.com> wrote:
> Hello VTK users,
>
> I currently have a VTK project that I'm building a GUI for - and I
> need to embed a vtkRenderingWindow into a Java window within a
> panel/Jframe instance. Any guidance (or questions) on this would be
> welcome.
>
> Best,
> Ambar
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



More information about the vtkusers mailing list