What is the difference between stackpane and root in JavaFX?
•
Java
I'm doing pie charts for JavaFX practice The following is the code for developing pie chart If I use group and stackpane, I find no difference in output I have commented on the group section Just hovering between the two
import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.chart.PieChart; import javafx.scene.chart.PieChart.Data; import javafx.scene.layout.StackPane; import javafx.stage.Stage; public class ChartApp1 extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { PieChart pieChart = new PieChart(); //Group p=new Group(); pieChart.setData(getChartData()); primaryStage.setTitle("PieChart"); StackPane root = new StackPane(); root.getChildren().add(pieChart); //p.getChildren().add(pieChart); primaryStage.setScene(new Scene(root,400,250)); primaryStage.show(); } private ObservableList<PieChart.Data> getChartData() { ObservableList<PieChart.Data> answer = FXCollections.observableArrayList(); answer.addAll(new PieChart.Data("java",17.56),new PieChart.Data("C",17.06),new PieChart.Data("C++",8.25),new PieChart.Data("C#",8.20),new PieChart.Data("ObjectiveC",6.8),new PieChart.Data("PHP",6.0),new PieChart.Data("(Visual)Basic",4.76),new PieChart.Data("Other",31.37)); return answer; } }
Solution
According to the official documentation,
Although the official documentation of the group indicates
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码