javafx中的stackpane和root有什么区别? [英] what is the difference between stackpane and root in javafx?

查看:120
本文介绍了javafx中的stackpane和root有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为javafx练习饼图.以下是开发饼图的代码.如果我使用GroupStackPane进行操作,我发现输出没有差异.我已经对Group部分进行了注释.只是在两者之间徘徊.

I was practicing for javafx for doing pie chart. Following are the codes for developing pie chart. If i do with the Group and with the StackPane,I find no difference in the output.I have commented the Group part.Just wandering the difference 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;
}
}

推荐答案

根据官方

StackPane 将其子级放在从后到前的堆栈中.子级的z顺序由子级列表的顺序定义 第0个孩子是最下面的孩子,最后一个孩子是最上面的孩子.如果有边界 和/或填充已设置,孩子们将被布置在 这些插图.

StackPane lays out its children in a back-to-front stack. The z-order of the children is defined by the order of the children list with the 0th child being the bottom and last child on top. If a border and/or padding have been set, the children will be layed out within those insets.

堆栈窗格将尝试调整大小以填充每个孩子 内容区域.如果无法调整孩子的尺寸以填满堆栈窗格 (由于无法调整大小或由于其最大尺寸而无法调整) 然后将使用对齐方式在该区域内对齐 属性,默认为Pos.CENTER

The stackpane will attempt to resize each child to fill its content area. If the child could not be sized to fill the stackpane (either because it was not resizable or its max size prevented it) then it will be aligned within the area using the alignment property, which defaults to Pos.CENTER

虽然正式的文档 Group类指出

一个 Group 节点包含一个 ObservableList 子项,这些子项是 依次渲染 渲染.小组将承担其子女的集体责任,而不是直接 可调整大小.

A Group node contains an ObservableList of children that are rendered in order whenever this node is rendered. A Group will take on the collective bounds of its children and is not directly resizable.

应用于组的任何变换,效果或状态将应用于 该组的所有孩子.这样的变换和效果不会 包含在该组的布局范围内,但是如果进行变换和 效果直接设置在该组的子级上,这些将是 包含在该组的布局范围内.

Any transform, effect, or state applied to a Group will be applied to all children of that group. Such transforms and effects will NOT be included in this Group's layout bounds, however if transforms and effects are set directly on children of this Group, those will be included in this Group's layout bounds.

默认情况下,网上论坛会将其可调整大小的可管理子级自动调整大小"为 其在布局过程中的首选尺寸以确保区域 和控件的大小随其状态的变化而适当调整.如果 应用程序需要禁用此自动调整大小的行为,那么它应该 将autoSizeChildren设置为false并了解是否首选 孩子的大小会改变,他们不会自动调整大小.

By default, a Group will "auto-size" its managed resizable children to their preferred sizes during the layout pass to ensure that Regions and Controls are sized properly as their state changes. If an application needs to disable this auto-sizing behavior, then it should set autoSizeChildren to false and understand that if the preferred size of the children change, they will not automatically resize.

这篇关于javafx中的stackpane和root有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆