public void start(Stage stage) {
HBox lHBox = new HBox();
{
GridPane lGridPane = new GridPane();
lGridPane.setVgap(5.0);
lGridPane.setPadding(new Insets(5.0));
int lRowIdx = 0;
{
lGridPane.add(new Label("Empty list"), 0, lRowIdx);
ListSpinner<String> lSpinner = new ListSpinner<String>();
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("Cyclic list"), 0, lRowIdx);
ListSpinner<String> lSpinner = new ListSpinner<String>("a", "b", "c")
.withCyclic(true)
;
lGridPane.add(lSpinner, 1, lRowIdx);
final TextField lValueTextField = new TextField();
lValueTextField.textProperty().bind(lSpinner.valueProperty());
lGridPane.add(lValueTextField, 2, lRowIdx++);
}
{
lGridPane.add(new Label("Cyclic list with null"), 0, lRowIdx);
ListSpinner<String> lSpinner = new ListSpinner<String>( "a", "b", "c", null )
.withCyclic(true)
;
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("Editable cyclic list"), 0, lRowIdx);
ListSpinner<String> lSpinner = new ListSpinner<String>( "a", "b", "c", "d", "e" )
.withCyclic(true)
.withEditable(true)
.withStringConverter(StringConverterFactory.forString())
;
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("Editable and adding cyclic list"), 0, lRowIdx);
final ObservableList<String> lObservableList = FXCollections.observableArrayList("a", "b", "c", "d", "e");
ListSpinner<String> lSpinner = new ListSpinner<String>( lObservableList )
.withCyclic(true)
.withEditable(true)
.withStringConverter(StringConverterFactory.forString())
.withAddCallback(new Callback<String, Integer>()
{
@Override
public Integer call(String text)
{
lObservableList.add(text);
return lObservableList.size() - 1; // notify spinner the value is appended at the end
}
})
;
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("Observable list, 'z' prepended"), 0, lRowIdx);
final ObservableList<String> lObservableList = FXCollections.observableArrayList("a", "b", "c", "d", "e");
ListSpinner<String> lSpinner = new ListSpinner<String>( lObservableList );
lObservableList.add(0, "z");
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("Observable list, first removed"), 0, lRowIdx);
final ObservableList<String> lObservableList = FXCollections.observableArrayList("a", "b", "c", "d", "e");
ListSpinner<String> lSpinner = new ListSpinner<String>( lObservableList );
lObservableList.remove("a");
lGridPane.add(lSpinner, 1, lRowIdx++);
}
// {
// lGridPane.add(new Label("Observable list, emptied"), 0, lRowIdx);
// final ObservableList<String> lObservableList = FXCollections.observableArrayList("a", "b", "c", "d", "e");
// ListSpinner<String> lSpinner = new ListSpinner<String>( lObservableList );
// lObservableList.clear(); // TODO: causes exception
// lGridPane.add(lSpinner, 1, lRowIdx++);
// }
{
lGridPane.add(new Label("BigInteger range"), 0, lRowIdx);
ListSpinner<BigInteger> lSpinner = new ListSpinner<BigInteger>(new ListSpinnerBigIntegerList(BigInteger.valueOf(Long.MIN_VALUE), BigInteger.valueOf(Long.MIN_VALUE + 1000)));
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("Integer range"), 0, lRowIdx);
ListSpinner<Integer> lSpinner = new ListSpinner<Integer>(new ListSpinnerIntegerList());
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("Integer range 10..110"), 0, lRowIdx);
ListSpinner<Integer> lSpinner = new ListSpinner<Integer>(10, 110);
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("Integer range 10..110 with setIndex 50"), 0, lRowIdx);
ListSpinner<Integer> lSpinner = new ListSpinner<Integer>(10, 110);
lSpinner.setIndex(50);
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("Integer range 0..1000 step 10"), 0, lRowIdx);
ListSpinner<Integer> lSpinner = new ListSpinner<Integer>(0, 100, 10);
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("Integer range -10..10"), 0, lRowIdx);
ListSpinner<Integer> lSpinner = new ListSpinner<Integer>(-10, 10);
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("Integer range 10..-10"), 0, lRowIdx);
ListSpinner<Integer> lSpinner = new ListSpinner<Integer>(10, -10);
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("align right"), 0, lRowIdx);
ListSpinner<String> lSpinner = new ListSpinner<String>( "a", "b", "c", "d", "e" );
lSpinner.setStyle("-fxx-value-alignment:CENTER_RIGHT;");
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("align right"), 0, lRowIdx);
ListSpinner<String> lSpinner = new ListSpinner<String>( "a", "b", "c", "d", "e" )
.withEditable(true)
.withStringConverter(StringConverterFactory.forString())
;
lSpinner.setStyle("-fxx-value-alignment:CENTER_RIGHT;");
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("Integer range 0..100 with %"), 0, lRowIdx);
ListSpinner<Integer> lSpinner = new ListSpinner<Integer>(0, 100)
.withPostfix("%")
;
lSpinner.setStyle("-fxx-value-alignment:CENTER_RIGHT;");
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("Integer range 0..100 with %"), 0, lRowIdx);
ListSpinner<Integer> lSpinner = new ListSpinner<Integer>(0, 100)
.withPostfix("%")
.withEditable(true)
.withStringConverter(StringConverterFactory.forInteger())
;
lSpinner.setStyle("-fxx-value-alignment:CENTER_RIGHT;");
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("Integer currency 0..100"), 0, lRowIdx);
ListSpinner<Integer> lSpinner = new ListSpinner<Integer>(0, 100)
.withPrefix("$ ")
;
lSpinner.setStyle("-fxx-value-alignment:CENTER_RIGHT;");
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("Integer currency 0..100"), 0, lRowIdx);
final ListSpinner<Integer> lSpinner = new ListSpinner<Integer>(0, 100)
.withPrefix("$ ")
.withEditable(true)
.withStringConverter(StringConverterFactory.forInteger())
;
lSpinner.setStyle("-fxx-value-alignment:CENTER_RIGHT;");
Button lButton = new Button("change CSS");
lButton.onMouseClickedProperty().set(new EventHandler<MouseEvent>()
{
@Override
public void handle(MouseEvent arg0)
{
//lSpinner.setStyle("-fxx-arrow-position:SPLIT;");
//lSpinner.setStyle("-fxx-arrow-direction:VERTICAL;;");
lSpinner.setStyle("-fxx-value-alignment:CENTER_LEFT; -fxx-arrow-direction:VERTICAL; -fxx-arrow-position:SPLIT;");
}
});
lGridPane.add(lButton, 2, lRowIdx);
lGridPane.add(lSpinner, 1, lRowIdx++);
}
lHBox.getChildren().add(lGridPane);
}
{
GridPane lGridPane = new GridPane();
lGridPane.setVgap(5.0);
lGridPane.setPadding(new Insets(5.0));
int lRowIdx = 0;
// arrow position
{
lGridPane.add(new Label("DEFAULT"), 0, lRowIdx);
ListSpinner<String> lSpinner = new ListSpinner<String>("a", "b", "c");
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("HORIZONTAL LEADING"), 0, lRowIdx);
ListSpinner<String> lSpinner = new ListSpinner<String>("a", "b", "c");
lSpinner.setStyle("-fxx-arrow-direction:HORIZONTAL; -fxx-arrow-position:LEADING;");
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("HORIZONTAL TRAILING"), 0, lRowIdx);
ListSpinner<String> lSpinner = new ListSpinner<String>("a", "b", "c");
lSpinner.setStyle("-fxx-arrow-direction:HORIZONTAL; -fxx-arrow-position:TRAILING;");
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("HORIZONTAL SPLIT"), 0, lRowIdx);
ListSpinner<String> lSpinner = new ListSpinner<String>("a", "b", "c");
lSpinner.setStyle("-fxx-arrow-direction:HORIZONTAL; -fxx-arrow-position:SPLIT;");
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("VERTICAL LEADING"), 0, lRowIdx);
ListSpinner<String> lSpinner = new ListSpinner<String>("a", "b", "c");
lSpinner.setStyle("-fxx-arrow-direction:VERTICAL; -fxx-arrow-position:LEADING;");
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("VERTICAL TRAILING"), 0, lRowIdx);
ListSpinner<String> lSpinner = new ListSpinner<String>("a", "b", "c");
lSpinner.setStyle("-fxx-arrow-direction:VERTICAL; -fxx-arrow-position:TRAILING;");
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("VERTICAL SPLIT"), 0, lRowIdx);
ListSpinner<String> lSpinner = new ListSpinner<String>("a", "b", "c");
lSpinner.setStyle("-fxx-arrow-direction:VERTICAL; -fxx-arrow-position:SPLIT;");
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("CSS"), 0, lRowIdx);
ListSpinner<String> lSpinner = new ListSpinner<String>("a", "b", "c");
lGridPane.add(lSpinner, 1, lRowIdx++);
lSpinner.setId("TheSpinner");
}
{
lGridPane.add(new Label("HORIZONTAL LEADING"), 0, lRowIdx);
ListSpinner<String> lSpinner = new ListSpinner<String>("a", "b", "c").withEditable(true);
lSpinner.setStyle("-fxx-arrow-direction:HORIZONTAL; -fxx-arrow-position:LEADING;");
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("HORIZONTAL TRAILING"), 0, lRowIdx);
ListSpinner<String> lSpinner = new ListSpinner<String>("a", "b", "c").withEditable(true);
lSpinner.setStyle("-fxx-arrow-direction:HORIZONTAL; -fxx-arrow-position:TRAILING;");
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("HORIZONTAL SPLIT"), 0, lRowIdx);
ListSpinner<String> lSpinner = new ListSpinner<String>("a", "b", "c").withEditable(true);
lSpinner.setStyle("-fxx-arrow-direction:HORIZONTAL; -fxx-arrow-position:SPLIT;");
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("VERTICAL LEADING"), 0, lRowIdx);
ListSpinner<String> lSpinner = new ListSpinner<String>("a", "b", "c").withEditable(true);
lSpinner.setStyle("-fxx-arrow-direction:VERTICAL; -fxx-arrow-position:LEADING;");
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("VERTICAL TRAILING"), 0, lRowIdx);
ListSpinner<String> lSpinner = new ListSpinner<String>("a", "b", "c").withEditable(true);
lSpinner.setStyle("-fxx-arrow-direction:VERTICAL; -fxx-arrow-position:TRAILING;");
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("VERTICAL SPLIT"), 0, lRowIdx);
ListSpinner<String> lSpinner = new ListSpinner<String>("a", "b", "c").withEditable(true);
lSpinner.setStyle("-fxx-arrow-direction:VERTICAL; -fxx-arrow-position:SPLIT;");
lGridPane.add(lSpinner, 1, lRowIdx++);
}
{
lGridPane.add(new Label("CSS SPLIT"), 0, lRowIdx);
final ListSpinner<String> lSpinner = new ListSpinner<String>("a", "b", "c").withEditable(true);
lGridPane.add(lSpinner, 1, lRowIdx++);
lSpinner.setId("TheEditableSpinner");
}
lHBox.getChildren().add(lGridPane);
}