Advertisement
Guest User

swing intergration

a guest
Jul 2nd, 2015
48
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.66 KB | None
  1. import java.awt.*;
  2.  
  3. import javax.swing.*;
  4.  
  5. import vtk.*;
  6.  
  7. public class JFrameRenderer extends JFrame
  8. {
  9.  
  10.   static {
  11.     for (vtkNativeLibrary lib : vtkNativeLibrary.values()) {
  12.         try {  
  13.                  System.loadLibrary(lib.GetLibraryName());
  14.             } catch(UnsatisfiedLinkError e) {
  15.             }
  16.     }
  17.   }
  18.  
  19.   public JFrameRenderer()
  20.   {
  21.     // Create a sphere source
  22.     vtkCubeSource cube = new vtkCubeSource();
  23.  
  24.     // Create a sphere mapper
  25.     vtkPolyDataMapper cubeMapper = new vtkPolyDataMapper();
  26.     cubeMapper.SetInputConnection(cube.GetOutputPort());
  27.  
  28.     //create sphere actor
  29.     vtkActor cubeActor = new vtkActor();
  30.     cubeActor.SetMapper(cubeMapper);
  31.  
  32.     // Create a render window panel to display the sphere
  33.     vtkRenderWindowPanel renderWindowPanel = new vtkRenderWindowPanel();
  34.     renderWindowPanel.setPreferredSize(new Dimension(600, 600));
  35.     renderWindowPanel.setInteractorStyle(new vtkInteractorStyleTrackballCamera());
  36.  
  37.     add(renderWindowPanel, BorderLayout.CENTER);
  38.  
  39.     renderWindowPanel.GetRenderer().AddActor(cubeActor);
  40.   }
  41.  
  42.   public static void main(String[] args)
  43.   {
  44.     try
  45.     {
  46.       javax.swing.SwingUtilities.invokeLater(new Runnable()
  47.       {
  48.         public void run()
  49.         {
  50.           JPopupMenu.setDefaultLightWeightPopupEnabled(false);
  51.           ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
  52.  
  53.           JFrame frame = new JFrameRenderer();
  54.           frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  55.           frame.pack();
  56.           frame.setVisible(true);
  57.         }
  58.       });      
  59.     }
  60.     catch (Exception e)
  61.     {
  62.       e.printStackTrace();
  63.     }
  64.   }
  65. }
Advertisement
RAW Paste Data Copied
Advertisement