-
Bug
-
Resolution: Duplicate
-
P4
-
7u6
-
2.2.0b15
Use code:
import javafx.application.Application;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.control.cell.CheckBoxListCell;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Callback;
import javafx.util.StringConverter;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
VBox vb = new VBox();
final ListView lv = new ListView();
lv.getItems().addAll(new DataItem(), new DataItem(), new DataItem());
Button b = new Button("Press me");
b.setOnAction(new EventHandler<ActionEvent>(){
public void handle(ActionEvent t) {
Callback<DataItem, ObservableValue<Boolean>> callback1 = new Callback<DataItem, ObservableValue<Boolean>>() {
public ObservableValue<Boolean> call(final DataItem p) {
return p.someData;
}
};
lv.setCellFactory(CheckBoxListCell.forListView(callback1, new CellCustomStringConverter()));
}
});
vb.getChildren().addAll(lv, b);
Scene scene = new Scene(vb, 300, 300);
stage.setScene(scene);
stage.show();
}
class DataItem {
public ObservableValue<Boolean> someData = new SimpleBooleanProperty(true);
}
public class CellCustomStringConverter extends StringConverter {
public static final String TO_STRING_PREFIX = "tsc ";
public static final String FROM_STRING_PREFIX = "fsc ";
@Override
public String toString(Object t) {
System.out.println("Called to string");
return TO_STRING_PREFIX + t != null ? t.toString() : "null";
}
@Override
public Object fromString(String string) {
System.out.println("called from string");
return null;
}
}
}
When I Press button, I see output:
Called to string
Called to string
Called to string
Called to string
But I don't see "tsc " in the beginning of list items, when checkbox appears.
import javafx.application.Application;
import javafx.beans.property.SimpleBooleanProperty;
import javafx.beans.value.ObservableValue;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ListView;
import javafx.scene.control.cell.CheckBoxListCell;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import javafx.util.Callback;
import javafx.util.StringConverter;
public class Main extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage stage) throws Exception {
VBox vb = new VBox();
final ListView lv = new ListView();
lv.getItems().addAll(new DataItem(), new DataItem(), new DataItem());
Button b = new Button("Press me");
b.setOnAction(new EventHandler<ActionEvent>(){
public void handle(ActionEvent t) {
Callback<DataItem, ObservableValue<Boolean>> callback1 = new Callback<DataItem, ObservableValue<Boolean>>() {
public ObservableValue<Boolean> call(final DataItem p) {
return p.someData;
}
};
lv.setCellFactory(CheckBoxListCell.forListView(callback1, new CellCustomStringConverter()));
}
});
vb.getChildren().addAll(lv, b);
Scene scene = new Scene(vb, 300, 300);
stage.setScene(scene);
stage.show();
}
class DataItem {
public ObservableValue<Boolean> someData = new SimpleBooleanProperty(true);
}
public class CellCustomStringConverter extends StringConverter {
public static final String TO_STRING_PREFIX = "tsc ";
public static final String FROM_STRING_PREFIX = "fsc ";
@Override
public String toString(Object t) {
System.out.println("Called to string");
return TO_STRING_PREFIX + t != null ? t.toString() : "null";
}
@Override
public Object fromString(String string) {
System.out.println("called from string");
return null;
}
}
}
When I Press button, I see output:
Called to string
Called to string
Called to string
Called to string
But I don't see "tsc " in the beginning of list items, when checkbox appears.