JavaFX表是一种基于Java的图形用户界面(GUI)技术,它可以帮助开发人员快速创建功能强大的应用程序。它使用JavaFX脚本语言来构建GUI,并且可以在多种平台上运行,包括Windows、Mac OS X和Linux。
JavaFX表具有许多优点,其中之一是它可以帮助开发人员快速创建功能强大的应用程序。它使用JavaFX脚本语言来构建GUI,而不需要学习复杂的API或者使用复杂的工具。此外,它还提供了一个易于使用的图形界面编辑器,可以帮助开发人员快速创建GUI。
此外,JavaFX表还具有很好的性能特性。它使用OpenGL ES 2.0 API来渲染图形界面,这意味着它可以在低端计算机上运行流畅而不会减慢性能。此外,它还具有内存优化功能,可以帮助减少内存占用量。
此外,JavaFX表也具有很好的扩展性特性。它支持各种扩展API(如Swing、SWT、AWT、JOGL、JOGL2、OpenGL ES 2.0等),因此开发人员可以根据需要扩展应用程序的功能。
public class MyTable extends TableView { private TableColumn nameColumn; public MyTable() { nameColumn = new TableColumn("Name"); getColumns().add(nameColumn); } public void setName(String name) { nameColumn.setCellValueFactory(new PropertyValueFactory<>(name)); } }
条形图是具有可以是垂直或水平的矩形条的双轴图表。
import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.chart.BarChart; import javafx.scene.chart.CategoryAxis; import javafx.scene.chart.NumberAxis; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class Main extends Application { @Override public void start(final Stage stage) { stage.setTitle(""); stage.setWidth(500); stage.setHeight(500); Scene scene = new Scene(new Group()); VBox root = new VBox(); NumberAxis lineYAxis = new NumberAxis(0,100,10); CategoryAxis lineXAxis = new CategoryAxis(); BarChart barChart = new BarChart(lineXAxis,lineYAxis); lineYAxis.setLabel("Sales"); lineXAxis.setLabel("Products"); root.getChildren().addAll(barChart); scene.setRoot(root); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); } }
上面的代码生成以下结果。
import javafx.animation.Animation; import javafx.animation.KeyFrame; import javafx.animation.Timeline; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.chart.BarChart; import javafx.scene.chart.CategoryAxis; import javafx.scene.chart.NumberAxis; import javafx.scene.chart.XYChart; import javafx.stage.Stage; import javafx.util.Duration; public class Main extends Application { final static String itemA = "A"; final static String itemB = "B"; final static String itemC = "F"; @Override public void start(Stage stage) { final NumberAxis xAxis = new NumberAxis(); final CategoryAxis yAxis = new CategoryAxis(); final BarChart<Number, String> bc = new BarChart<Number, String>(xAxis, yAxis); bc.setTitle("Summary"); xAxis.setLabel("Value"); xAxis.setTickLabelRotation(90); yAxis.setLabel("Item"); XYChart.Series series1 = new XYChart.Series(); series1.setName("2003"); series1.getData().add(new XYChart.Data(2, itemA)); series1.getData().add(new XYChart.Data(20, itemB)); series1.getData().add(new XYChart.Data(10, itemC)); XYChart.Series series2 = new XYChart.Series(); series2.setName("2004"); series2.getData().add(new XYChart.Data(50, itemA)); series2.getData().add(new XYChart.Data(41, itemB)); series2.getData().add(new XYChart.Data(45, itemC)); XYChart.Series series3 = new XYChart.Series(); series3.setName("2005"); series3.getData().add(new XYChart.Data(45, itemA)); series3.getData().add(new XYChart.Data(44, itemB)); series3.getData().add(new XYChart.Data(18, itemC)); Timeline tl = new Timeline(); tl.getKeyFrames().add(new KeyFrame(Duration.millis(500), new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { for (XYChart.Series<Number, String> series : bc.getData()) { for (XYChart.Data<Number, String> data : series.getData()) { data.setXValue(Math.random() * 100); } } } })); tl.setCycleCount(Animation.INDEFINITE); tl.play(); Scene scene = new Scene(bc, 800, 600); bc.getData().addAll(series1, series2, series3); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); } }
上面的代码生成以下结果。
import javafx.animation.Animation; import javafx.animation.KeyFrame; import javafx.animation.Timeline; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.chart.BarChart; import javafx.scene.chart.CategoryAxis; import javafx.scene.chart.NumberAxis; import javafx.scene.chart.XYChart; import javafx.stage.Stage; import javafx.util.Duration; public class Main extends Application { final static String itemA = "A"; final static String itemB = "B"; final static String itemC = "F"; @Override public void start(Stage stage) { final NumberAxis xAxis = new NumberAxis(); final CategoryAxis yAxis = new CategoryAxis(); final BarChart<Number, String> bc = new BarChart<Number, String>(xAxis, yAxis); bc.setTitle("Summary"); xAxis.setLabel("Value"); xAxis.setTickLabelRotation(90); yAxis.setLabel("Item"); XYChart.Series series1 = new XYChart.Series(); series1.setName("2003"); series1.getData().add(new XYChart.Data(2, itemA)); series1.getData().add(new XYChart.Data(20, itemB)); series1.getData().add(new XYChart.Data(10, itemC)); XYChart.Series series2 = new XYChart.Series(); series2.setName("2004"); series2.getData().add(new XYChart.Data(50, itemA)); series2.getData().add(new XYChart.Data(41, itemB)); series2.getData().add(new XYChart.Data(45, itemC)); XYChart.Series series3 = new XYChart.Series(); series3.setName("2005"); series3.getData().add(new XYChart.Data(45, itemA)); series3.getData().add(new XYChart.Data(44, itemB)); series3.getData().add(new XYChart.Data(18, itemC)); Timeline tl = new Timeline(); tl.getKeyFrames().add(new KeyFrame(Duration.millis(500), new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent actionEvent) { for (XYChart.Series<Number, String> series : bc.getData()) { for (XYChart.Data<Number, String> data : series.getData()) { data.setXValue(Math.random() * 100); } } } })); tl.setCycleCount(Animation.INDEFINITE); tl.play(); Scene scene = new Scene(bc, 800, 600); bc.getData().addAll(series1, series2, series3); stage.setScene(scene); stage.show(); } public static void main(String[] args) { launch(args); } }
上面的代码生成以下结果。
import java.util.Arrays; import javafx.application.Application; import javafx.collections.FXCollections; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.chart.CategoryAxis; import javafx.scene.chart.NumberAxis; import javafx.scene.chart.StackedBarChart; import javafx.scene.chart.XYChart; import javafx.stage.Stage; public class Main extends Application { public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) { Group root = new Group(); final CategoryAxis xAxis = new CategoryAxis(); final NumberAxis yAxis = new NumberAxis(); xAxis.setLabel("Month"); xAxis.setCategories(FXCollections.<String> observableArrayList(Arrays.asList( "January", "February", "March"))); yAxis.setLabel("Value"); final StackedBarChart<String,Number> stackedBarChart = new StackedBarChart<String,Number>(xAxis,yAxis); stackedBarChart.setTitle("StackedBarChart"); XYChart.Series<String,Number> series1 = new XYChart.Series(); series1.setName("XYChart.Series 1"); series1.getData().add(new XYChart.Data("January", 100)); series1.getData().add(new XYChart.Data("February", 200)); series1.getData().add(new XYChart.Data("March", 50)); XYChart.Series<String,Number> series2 = new XYChart.Series(); series2.setName("XYChart.Series 2"); series2.getData().add(new XYChart.Data("January", 150)); series2.getData().add(new XYChart.Data("February", 100)); series2.getData().add(new XYChart.Data("March", 60)); stackedBarChart.getData().addAll(series1, series2); root.getChildren().addAll(stackedBarChart); primaryStage.setScene(new Scene(root, 500, 400)); primaryStage.show(); } }
上面的代码生成以下结果。
Java Lambda行为参数化我们可以将lambda表达式作为参数传递给方法。例子以下代码创建了一个名为 Calculator 的函数接口。在 Calc...
Java脚本教程 -Java脚本绑定绑定是一组键/值对,键必须是非空的非空字符串。Java Bindings是Bindings接口的一个实例。SimpleBind...
Java脚本教程 - Java编译脚本脚本引擎允许以Java类的形式编译脚本,然后重复执行它。以下代码检查脚本引擎是否实现了可编译接口:...