【发布时间】:2017-01-24 00:33:14
【问题描述】:
我想声明一个包含两个面板的 JavaFX GridPane,左边的一个包含一个按钮。单击按钮时,右侧面板中会显示一个 LineChart。编码大概是这样的:
public class FormLineChart extends Application {
@Override
public void start(Stage stage) {
stage.setTitle("A Title");
//Create the grid for defining the GUI
GridPane grid = new GridPane();
// add gui objects to grid
...
//Create the chart
final LineChart<Number, Number> lineChart = new LineChart<>(xAxis, yAxis);
...
// Create the series and display the lineChart
lineChart.getData().add(series);
stage.setScene(scene);
Scene scene = new Scene(grid, 427, 319);
//How do we add 'lineChart' to scene as well as keeping 'grid'?
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
特别是可以在一个场景中结合“网格”和“线图”吗?目前只显示 GUI,因为 on 强制将场景设置为网格。
【问题讨论】:
-
将折线图和网格放在另一个窗格(某种)中,并使该窗格成为场景的根。或者,只需在按下按钮时将折线图添加到网格中的适当位置。
-
其实就像
grid.add(lineChart, 0,1);一样简单。您可以简单地将您的lineChart直接添加到网格中
标签: java javafx linechart scene gridpane