Custom Component: SelectableTitledPane

I’m working on a form to provide search criteria to find pictures in picmodo.
My goal is to provide a very easy to use interface.

Each search criteria is represented by a SelectableTitledPane which contains the parameter settings.
Basically I have set a CheckBox as graphic component of a TitlePane and modified the CSS of the Default-Skin com.sun.javafx.scene.control.skin.TitledPaneSkin.

picmodo search panel

The Checkbox‘s selectedProperty is bound to the expandedProperty of TitledPane to toggle the expand state and to get an indicator to enable / disable the criteria:

public class SelectableTitledPane extends TitledPane {

  private CheckBox checkBox;

  public SelectableTitledPane(String title, Node content) {
    super(title, content);
    checkBox = new CheckBox(title);
    checkBox.selectedProperty().
            bindBidirectional(this.expandedProperty());
    setExpanded(false);
    setContentDisplay(ContentDisplay.GRAPHIC_ONLY);
    setGraphic(checkBox);
    setSkin(new TitledPaneSkin(this));
    lookup(".arrow").
            setVisible(false);
    lookup(".title").
            setStyle("-fx-padding: 0 0 4 -10;"
            + "-fx-background-color: null;");
    lookup(".content").
            setStyle("-fx-background-color: null; -fx-padding:  0.2em 0.2em 0.2em 1.316667em;");
  }

  public BooleanProperty getSelectedProperty() {
    return checkBox.selectedProperty();
  }

  public boolean isSelected() {
    return checkBox.isSelected();
  }

  public void setSelected(boolean selected) {
    checkBox.setSelected(selected);
  }
}

Basically the SelectableTitledPane can then be used as a TitledPane, e.g.:

ComboBox ownerBox = ComboBoxBuilder.<AppUser>create().
            prefWidth(150).
            promptText(resourceBundle
            .getString("search.prompt.owner")).
            build();

SelectableTitledPaneownerParams = new SelectableTitledPane(resourceBundle
            .getString("search.checkbox.owner"), ownerBox);

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>