i am new to Java, but have been programming microprocessors since 1976.
When I posted a query in the Oracle form requesting help with binding, a gentleman wrote a goo chunk of the program that accepts data from a telnet session and displays it.
My only issue was that I am using Scene Builder with an AnchorPane, Image and labels to display the data. His example used an fxml file with a HBox and labels inside of that. So I changed the fxml file, but cannot get data to populate in the window. His complete code is at:
https://gist.github.com/james-d/95457d1ac1a90e063337
His fxml file looks like :
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.Label?>
<?import javafx.geometry.Insets?>
<HBox xmlns:fx="http://javafx.com/fxml/1" spacing="5"
alignment="CENTER" fx:controller="streamingdatafx.DisplayController">
<padding>
<Insets top="10" left="10" right="10" bottom="10"/>
</padding>
<Label text="Speed:"/>
<Label fx:id="speedLabel"/>
</HBox>Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.text.*?>
<?import javafx.scene.image.*?>
<?import java.lang.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.control.Label?>
<?import javafx.geometry.Insets?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="480.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<ImageView fitHeight="480.0" fitWidth="800.0" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../../../Documents/NetBeansProjects/Test/src/Main_Display.png" />
</image>
</ImageView>
<HBox prefHeight="100.0" prefWidth="200.0">
<children>
<Label text="Speed:" />
</children>
</HBox>
<Label id="speedLabel" layoutX="114.0" layoutY="146.0" prefHeight="70.0" prefWidth="191.0" textFill="#e8e3e3">
<font>
<Font size="48.0" />
</font>
</Label>
</children>
</AnchorPane>
Code: Select all
public class Main extends Application {
private DataStreamParser dataStream ;
@Override
public void start(Stage primaryStage) {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("Display.fxml"));
AnchorPane root = loader.load();
DisplayController controller = loader.getController();
dataStream = new DataStreamParser();
dataStream.speedProperty().addListener((obs, oldSpeed, newSpeed) -> {
// update controller on FX Application Thread:
Platform.runLater(() -> controller.setSpeed(newSpeed.doubleValue()));
});
Scene scene = new Scene(root,400,400);
primaryStage.setScene(scene);
primaryStage.show();
}The form will run and display speed, but the program throws an exception at at the line
Platform.runLater(() -> controller.setSpeed(newSpeed.doubleValue()));
Any suggestions would be welcome.
Kind regards,
David