apps/samples/Ensemble8/src/samples/java/ensemble/samples/controls/spinner/SpinnerApp.java
Print this page
*** 37,48 ****
import javafx.scene.Group;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory;
! import javafx.scene.layout.HBox;
! import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import java.util.Arrays;
/**
--- 37,48 ----
import javafx.scene.Group;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Spinner;
import javafx.scene.control.SpinnerValueFactory;
! import javafx.scene.layout.Pane;
! import javafx.scene.layout.TilePane;
import javafx.stage.Stage;
import java.util.Arrays;
/**
*** 68,129 ****
primaryStage.show();
}
public Parent createContent() {
- HBox intBlock = new HBox(30);
- HBox stringBlock = new HBox(30);
- HBox doubleBlock = new HBox(30);
-
String[] styles = {
"spinner", // defaults to arrows on right stacked vertically
Spinner.STYLE_CLASS_ARROWS_ON_RIGHT_HORIZONTAL,
Spinner.STYLE_CLASS_ARROWS_ON_LEFT_VERTICAL,
Spinner.STYLE_CLASS_ARROWS_ON_LEFT_HORIZONTAL,
Spinner.STYLE_CLASS_SPLIT_ARROWS_VERTICAL,
Spinner.STYLE_CLASS_SPLIT_ARROWS_HORIZONTAL
};
! Spinner[] intSpinners = new Spinner[styles.length];
! Spinner[] stringSpinners = new Spinner[styles.length];
! Spinner[] doubleSpinners = new Spinner[styles.length];
for (int i = 0; i < styles.length; i++) {
/* Integer spinners */
SpinnerValueFactory svf =
new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 99);
Spinner sp = new Spinner();
sp.setValueFactory(svf);
sp.getStyleClass().add(styles[i]);
sp.setPrefWidth(80);
! intSpinners[i] = sp;
/* Double spinners */
! svf = new SpinnerValueFactory.DoubleSpinnerValueFactory(0.0, 1.0,
0.5, 0.01);
! sp = new Spinner();
sp.setValueFactory(svf);
sp.getStyleClass().add(styles[i]);
sp.setPrefWidth(90);
! doubleSpinners[i] = sp;
/* String spinners */
ObservableList<String> items =
FXCollections.observableArrayList("Grace", "Matt", "Katie");
! svf = new SpinnerValueFactory.ListSpinnerValueFactory<>(items);
! sp = new Spinner();
sp.setValueFactory(svf);
sp.setPrefWidth(100);
sp.getStyleClass().add(styles[i]);
! stringSpinners[i] = sp;
}
! intBlock.getChildren().addAll(Arrays.asList(intSpinners));
! doubleBlock.getChildren().addAll(Arrays.asList(doubleSpinners));
! stringBlock.getChildren().addAll(Arrays.asList(stringSpinners));
!
! doubleBlock.setLayoutY(100);
! stringBlock.setLayoutY(200);
!
! return new VBox(25, intBlock, doubleBlock, stringBlock);
}
}
--- 68,131 ----
primaryStage.show();
}
public Parent createContent() {
String[] styles = {
"spinner", // defaults to arrows on right stacked vertically
Spinner.STYLE_CLASS_ARROWS_ON_RIGHT_HORIZONTAL,
Spinner.STYLE_CLASS_ARROWS_ON_LEFT_VERTICAL,
Spinner.STYLE_CLASS_ARROWS_ON_LEFT_HORIZONTAL,
Spinner.STYLE_CLASS_SPLIT_ARROWS_VERTICAL,
Spinner.STYLE_CLASS_SPLIT_ARROWS_HORIZONTAL
};
! TilePane tilePane = new TilePane();
! tilePane.setPrefColumns(6); //preferred columns
! tilePane.setPrefRows(3); //preferred rows
! tilePane.setHgap(20);
! tilePane.setVgap(30);
!
! Pane root = new Pane();
! root.setMinSize(Pane.USE_PREF_SIZE, Pane.USE_PREF_SIZE);
! root.setMaxSize(Pane.USE_PREF_SIZE, Pane.USE_PREF_SIZE);
for (int i = 0; i < styles.length; i++) {
/* Integer spinners */
SpinnerValueFactory svf =
new SpinnerValueFactory.IntegerSpinnerValueFactory(1, 99);
Spinner sp = new Spinner();
sp.setValueFactory(svf);
sp.getStyleClass().add(styles[i]);
sp.setPrefWidth(80);
! tilePane.getChildren().add(sp);
! }
+ for (int i = 0; i < styles.length; i++) {
/* Double spinners */
! SpinnerValueFactory svf =
! new SpinnerValueFactory.DoubleSpinnerValueFactory(0.0, 1.0,
0.5, 0.01);
! Spinner sp = new Spinner();
sp.setValueFactory(svf);
sp.getStyleClass().add(styles[i]);
sp.setPrefWidth(90);
! tilePane.getChildren().add(sp);
! }
+ for (int i = 0; i < styles.length; i++) {
/* String spinners */
ObservableList<String> items =
FXCollections.observableArrayList("Grace", "Matt", "Katie");
! SpinnerValueFactory svf =
! new SpinnerValueFactory.ListSpinnerValueFactory<>(items);
! Spinner sp = new Spinner();
sp.setValueFactory(svf);
sp.setPrefWidth(100);
sp.getStyleClass().add(styles[i]);
! tilePane.getChildren().add(sp);
}
! root.getChildren().add(tilePane);
! return root;
}
}