import javafx.application.Application; import javafx.event.EventHandler; import javafx.scene.DepthTest; import javafx.scene.Group; import javafx.scene.PerspectiveCamera; import javafx.scene.Scene; import javafx.scene.control.TabBuilder; import javafx.scene.control.TabPane; import javafx.scene.input.MouseEvent; import javafx.scene.paint.Color; import javafx.scene.shape.RectangleBuilder; import javafx.scene.text.Font; import javafx.scene.text.TextBuilder; import javafx.scene.transform.Rotate; import javafx.stage.Stage; /** * Basic example of 3D scene embedded in a tab pane and without a tab pane. * */ public class TabPane3DProblems extends Application { private final boolean useTabPane = false; /** * Default Constructor */ public TabPane3DProblems() { } @Override public void start(Stage stage) throws Exception { stage.setTitle("Depth buffer problems"); stage.setScene(createScene()); stage.show(); } private Scene createScene() { Color[] colors = new Color[] { Color.RED, Color.GREEN, Color.BLUE }; final Group shapes = new Group(); shapes.setDepthTest(DepthTest.ENABLE); for (int i = 0; i < colors.length; i++) { Color color = colors[i]; double z = i * 50; shapes.getChildren().add( RectangleBuilder.create().fill(color).width(100) .height(100).translateZ(z) .depthTest(DepthTest.ENABLE).build()); shapes.getChildren().add( TextBuilder.create().text("Foo bar " + i) .font(Font.font("Arial", 16)).layoutX(20) .layoutY(40).translateZ(z - 5) .depthTest(DepthTest.ENABLE).build()); } shapes.setTranslateZ(100); // push back so camera can see everything final Group root = new Group(); root.setDepthTest(DepthTest.ENABLE); root.getChildren().add(shapes); Scene scene = null; if (useTabPane) { TabPane tabPane = new TabPane(); tabPane.setDepthTest(DepthTest.ENABLE); tabPane.getTabs().add( TabBuilder.create().text("Tab 1").content(root).build()); scene = new Scene(tabPane, 300, 300, true); } else { scene = new Scene(root, 300, 300, true); } scene.setCamera(new PerspectiveCamera()); // basic rotate with mouse scene.setOnMouseDragged(new EventHandler() { @Override public void handle(MouseEvent event) { shapes.setRotationAxis(Rotate.X_AXIS); shapes.setRotate(event.getSceneY() % 360); } }); return scene; } /** * Start * * @param args */ public static void main(String[] args) { Application.launch(TabPane3DProblems.class, (String[]) null); } }