I have been searching a lot for any good examples of the use of a ControlsFX PropertySheet but couldn’t find anything but this.
https://www.google.nl/search?q=Main.java+amazonaws.com&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:nl:official&client=firefox-a&channel=sb&gfe_rd=cr&ei=d5aeU5bvBI3k-gan94HQBA#channel=sb&q=https%3A%2F%2Fbitbucket-assetroot.s3.amazonaws.com%2Fcontrolsfx%2Fcontrolsfx+Main.java&rls=org.mozilla:nl:official
In this example, the ObservableList items which includes NameItem objects, is added to the PropertySheet object in its constructor just like the documentation tells.
http://controlsfx.bitbucket.org/org/controlsfx/control/PropertySheet.html
However, as this documentation says, a column of a PropertySheet “provides a PropertyEditor that allows the end user the means to manipulate the property”. It even says that there is a “CheckEditor, ChoiceEditor, TextEditor and FontEditor, among the many editors that are available in the Editors package.”.
I don’t want to be limited to my NameItem example. I also want to add check boxes, choice boxes and other dynamic editor elements. Can anyone please give an example on how to use one or more of the editors to build a simple PropertySheet?
Recently I've been working on Javafx with PropertySheet
, below is the simple and quick practice:
first we need model class to reflect the gui:
public class Person {
int age;
boolean isLive = true;
String name = "Yimkong";
// ... getter and setter method
}
Then is the Main class:
public class PropertiesSheetTest extends Application {
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Person bean = new Person();
ObservableList<PropertySheet.Item> properties = BeanPropertyUtils.getProperties(bean);
PropertySheet propertySheet = new PropertySheet(properties);
propertySheet.setSearchBoxVisible(false);
propertySheet.setModeSwitcherVisible(false);
DefaultPropertyEditorFactory defaultPropertyEditorFactory = new DefaultPropertyEditorFactory();
propertySheet.setPropertyEditorFactory(new Callback<PropertySheet.Item, PropertyEditor<?>>() {
@Override
public PropertyEditor<?> call(PropertySheet.Item param) {
if(param.getName().equals("age")){
List<Integer> ageList = new ArrayList<>();
ageList.add(3);
ageList.add(5);
ageList.add(10);
return Editors.createChoiceEditor(param,ageList);
}
return defaultPropertyEditorFactory.call(param);
}
});
VBox vBox = new VBox(propertySheet);
Scene scene = new Scene(vBox);
primaryStage.setScene(scene);
primaryStage.show();
}
}
Here is the result:
Advantages:
This basically satisfy most scenarios.By the way, it can also support Enum field in model class with ChoiceEditor as Default.😝
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With