Results 1 to 3 of 3
  1. #1
    dfansler is offline Member
    Join Date
    Oct 2014
    Posts
    2
    Rep Power
    0

    Default Binding between Scene Builder TextField and javafx

    I am new to java and javafx. I have developed a background and populated it with TextFields (ie GearField, SpeedField, TachField - in case you might not have guessed, i am working on the display for a car. Data will come into the program via RS232 in sentences that will be parsed and the data displayed. I have been trying to figure out how to bind declared variables in my controller to the TextFields in the Scene Builder FXML file. I have read everything i could find, but the examples appear to be way more complicated than what I am trying to do - one way binding - change the value of a variable in the controller and have it change the value of the TextField on the display.

    I can get the scene to show up when I run the program, but i am at a lost as to how to change the values of the items in the scene.

    Any suggestions would be appreciated.
    Kind regards,
    David

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: Binding between Scene Builder TextField and javafx

    Are the variables in your controller of a type that implements Observable?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    dfansler is offline Member
    Join Date
    Oct 2014
    Posts
    2
    Rep Power
    0

    Default Re: Binding between Scene Builder TextField and javafx

    No - I looked around to get an understanding of Observable, not quite sure I do at this point. I am going to post the pertinent code in hopes that will help: (thanks )


    public class VelocesDisplay extends Application {


    @Override
    public void start(Stage stage) throws Exception {

    Parent root = FXMLLoader.load(getClass().getResource("Main_Displ ay.fxml"));

    Scene scene = new Scene(root);

    stage.setScene(scene);
    stage.show();
    }

    public class Main_DisplayController implements Initializable {
    @FXML
    private TextField GearField;

    @Override
    public void initialize(URL url, ResourceBundle rb) {
    // TODO

    init_bindings();
    }
    @FXML
    private TextField GearField;
    public void init_bindings() {
    TextField Gear = new TextField();
    GearField.textProperty().bind(Gear.textProperty()) ;
    }
    }

    FMXL file (showing only one textfield)
    <AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="480.0" prefWidth="800.0" stylesheets="@Text%20Style.css" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="veloces.display.Main_DisplayControl ler">
    <children>
    </TextField>
    <TextField id="GearField" alignment="CENTER" layoutX="14.0" layoutY="69.0" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="180.0" prefWidth="174.0" stylesheets="@Text%20Style.css" text="N">
    <font>
    <Font name="Ethnocentric" size="180.0" />
    </font>
    <padding>
    </children>
    </AnchorPane>

Similar Threads

  1. JavaFX scene builder
    By JavaPete in forum JavaFX
    Replies: 2
    Last Post: 07-17-2014, 12:23 AM
  2. JavaFX Book | Learn JavaFX More In Depth
    By SnakeDoc in forum JavaFX
    Replies: 0
    Last Post: 05-17-2013, 11:10 PM
  3. JavaFX Script and JavaFX Mobile
    By levent in forum Java Software
    Replies: 1
    Last Post: 01-27-2010, 04:48 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •