I'm trying to update a textfield with a numeric value and can't seem to figure out how to do so. The values I'm trying to add in the textfield are the values of the position on a slider, updating the textfield as you move it back and fourth. Any type of help would be appreciated. I'm not sure if you guys want me to post my code but its only a slider from 1-10 and a blank textfield in a gridpane so its not much help.
public class Main extends Application {
private static Slider fibSlider = new Slider(0,10,0);
private static Label indexLabel = new Label("Index: ");
private static int colIndex = 0;
private static int rowIndex = 0;
private static int topIndex = 0;
private static int rightIndex = 0;
private static int leftIndex = 0;
private static int bottomIndex = 0;
private static TextField tfIndex;
@Override
public void start(Stage primaryStage) {
fibSlider.setMajorTickUnit(1);
fibSlider.setMinorTickCount(0);
fibSlider.setShowTickLabels(true);
fibSlider.setShowTickMarks(true);
/* fibSlider.valueProperty().addListener(sl -> {
tfIndex.setText(fibSlider.getValue());
});
*/
GridPane mainGPane = buildGPane();
Scene mainScene = new Scene(mainGPane, 500, 200);
primaryStage.setTitle("ex");
primaryStage.setScene(mainScene);
primaryStage.show();
}
public static GridPane buildGPane() {
GridPane gPane = new GridPane();
gPane.setAlignment(Pos.CENTER);
gPane.setPadding(new Insets(topIndex=10,rightIndex=10,
bottomIndex=10,leftIndex=10));
gPane.setHgap(2);
gPane.setVgap(2);
gPane.add(fibSlider,colIndex=1,rowIndex=3);
gPane.add(indexLabel,colIndex=1,rowIndex=5);
gPane.add(tfIndex,colIndex=2,rowIndex=5);
return gPane;
}
public Main() {
tfIndex = new TextField();
}