[vtkusers] Problem with Render() in Java/Linux
    Toh Da Jun 
    tohdj at bii.a-star.edu.sg
       
    Mon Feb  7 21:25:30 EST 2005
    
    
  
Hi,
I'm using Linux + Java and making use of the vtkPanel and vtkCanvas to
develop a program.
After I had set up the renderwindow etc etc, and my GUI is up and
running, I clicked on a Menu option (public void ViewMedium()) and it
adds an actor into the Renderer.
When I did a count of the number of visible actors in the Renderer, the
number is correct, but I cannot see the new actor in the display.
Anybody know what's wrong with this? Thanks
tohdj
=======================================================================
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import vtk.*;
public class MCSCanvas extends JPanel {
  private vtkCanvas renWin;
  private AxesActor MCSAxesActor;
  private MediumActor MCSMediumActor;
  private boolean isDisplayed = false;
  public MCSCanvas() {
    setLayout(new BorderLayout());
    // Create the buttons.
    renWin = new vtkCanvas();
    add(renWin, BorderLayout.CENTER);
    AxesActor MCSAxesActor = new AxesActor(renWin.GetRenderer());
    renWin.GetRenderer().AddActor(MCSAxesActor);
    MCSMediumActor = new MediumActor(renWin.GetRenderer());
  }
  public void ViewMedium()
  {
    if (isDisplayed == false) {
	System.out.println(renWin.GetRenderer().VisibleActorCount());
	renWin.GetRenderer().AddActor(MCSMediumActor);
	renWin.Render();
        isDisplayed = true;
	System.out.println("ViewMedium ON");
	System.out.println(renWin.GetRenderer().VisibleActorCount());
    }
    else {
	System.out.println(renWin.GetRenderer().VisibleActorCount());
	renWin.GetRenderer().RemoveActor(MCSMediumActor);
	renWin.Render();
        isDisplayed = false;
	System.out.println("ViewMedium OFF");
	System.out.println(renWin.GetRenderer().VisibleActorCount());
    }
  }
  
  public void reSize()
  {
    renWin.reSize();
  }
  public static void main(String s[]) 
  {
    MCSCanvas panel = new MCSCanvas();
    MCSCanvas panel2 = new MCSCanvas();
	
    JFrame frame = new JFrame("VTK Canvas Test!");
    frame.getContentPane().setLayout(new GridLayout(2,1));
    frame.addWindowListener(new WindowAdapter() 
      {
        public void windowClosing(WindowEvent e) {System.exit(0);}
      });
    frame.getContentPane().add(panel);
    frame.getContentPane().add(panel2);
    frame.pack();
    frame.setVisible(true);
  }
}
    
    
More information about the vtkusers
mailing list