< prev index next >

modules/javafx.controls/src/main/java/javafx/scene/control/TableColumn.java

Print this page
rev 10598 : 8185767: Fix broken links in Javadocs


  54 import java.util.Map;
  55 import javafx.beans.property.ReadOnlyObjectProperty;
  56 import javafx.beans.property.ReadOnlyObjectWrapper;
  57 import javafx.beans.value.ObservableValue;
  58 import javafx.beans.value.WritableValue;
  59 
  60 /**
  61  * A {@link TableView} is made up of a number of TableColumn instances. Each
  62  * TableColumn in a table is responsible for displaying (and editing) the contents
  63  * of that column. As well as being responsible for displaying and editing data
  64  * for a single column, a TableColumn also contains the necessary properties to:
  65  * <ul>
  66  *    <li>Be resized (using {@link #minWidthProperty() minWidth}/{@link #prefWidthProperty() prefWidth}/{@link #maxWidthProperty() maxWidth}
  67  *      and {@link #widthProperty() width} properties)
  68  *    <li>Have its {@link #visibleProperty() visibility} toggled
  69  *    <li>Display {@link #textProperty() header text}
  70  *    <li>Display any {@link #getColumns() nested columns} it may contain
  71  *    <li>Have a {@link #contextMenuProperty() context menu} when the user
  72  *      right-clicks the column header area
  73  *    <li>Have the contents of the table be sorted (using
  74  *      {@link #comparatorProperty() comparator}, {@link #sortable sortable} and
  75  *      {@link #sortTypeProperty() sortType})
  76  * </ul>
  77  *
  78  * When creating a TableColumn instance, perhaps the two most important properties
  79  * to set are the column {@link #textProperty() text} (what to show in the column
  80  * header area), and the column {@link #cellValueFactory cell value factory}
  81  * (which is used to populate individual cells in the column). This can be
  82  * achieved using some variation on the following code:
  83  *
  84  * <pre>
  85  * {@code
  86  * ObservableList<Person> data = ...
  87  * TableView<Person> tableView = new TableView<Person>(data);
  88  *
  89  * TableColumn<Person,String> firstNameCol = new TableColumn<Person,String>("First Name");
  90  * firstNameCol.setCellValueFactory(new Callback<CellDataFeatures<Person, String>, ObservableValue<String>>() {
  91  *     public ObservableValue<String> call(CellDataFeatures<Person, String> p) {
  92  *         // p.getValue() returns the Person instance for a particular TableView row
  93  *         return p.getValue().firstNameProperty();
  94  *     }
  95  *  });
  96  * }
  97  * tableView.getColumns().add(firstNameCol);}</pre>
  98  *
  99  * This approach assumes that the object returned from <code>p.getValue()</code>
 100  * has a JavaFX {@link ObservableValue} that can simply be returned. The benefit of this




  54 import java.util.Map;
  55 import javafx.beans.property.ReadOnlyObjectProperty;
  56 import javafx.beans.property.ReadOnlyObjectWrapper;
  57 import javafx.beans.value.ObservableValue;
  58 import javafx.beans.value.WritableValue;
  59 
  60 /**
  61  * A {@link TableView} is made up of a number of TableColumn instances. Each
  62  * TableColumn in a table is responsible for displaying (and editing) the contents
  63  * of that column. As well as being responsible for displaying and editing data
  64  * for a single column, a TableColumn also contains the necessary properties to:
  65  * <ul>
  66  *    <li>Be resized (using {@link #minWidthProperty() minWidth}/{@link #prefWidthProperty() prefWidth}/{@link #maxWidthProperty() maxWidth}
  67  *      and {@link #widthProperty() width} properties)
  68  *    <li>Have its {@link #visibleProperty() visibility} toggled
  69  *    <li>Display {@link #textProperty() header text}
  70  *    <li>Display any {@link #getColumns() nested columns} it may contain
  71  *    <li>Have a {@link #contextMenuProperty() context menu} when the user
  72  *      right-clicks the column header area
  73  *    <li>Have the contents of the table be sorted (using
  74  *      {@link #comparatorProperty() comparator}, {@link #sortableProperty() sortable} and
  75  *      {@link #sortTypeProperty() sortType})
  76  * </ul>
  77  *
  78  * When creating a TableColumn instance, perhaps the two most important properties
  79  * to set are the column {@link #textProperty() text} (what to show in the column
  80  * header area), and the column {@link #cellValueFactoryProperty() cell value factory}
  81  * (which is used to populate individual cells in the column). This can be
  82  * achieved using some variation on the following code:
  83  *
  84  * <pre>
  85  * {@code
  86  * ObservableList<Person> data = ...
  87  * TableView<Person> tableView = new TableView<Person>(data);
  88  *
  89  * TableColumn<Person,String> firstNameCol = new TableColumn<Person,String>("First Name");
  90  * firstNameCol.setCellValueFactory(new Callback<CellDataFeatures<Person, String>, ObservableValue<String>>() {
  91  *     public ObservableValue<String> call(CellDataFeatures<Person, String> p) {
  92  *         // p.getValue() returns the Person instance for a particular TableView row
  93  *         return p.getValue().firstNameProperty();
  94  *     }
  95  *  });
  96  * }
  97  * tableView.getColumns().add(firstNameCol);}</pre>
  98  *
  99  * This approach assumes that the object returned from <code>p.getValue()</code>
 100  * has a JavaFX {@link ObservableValue} that can simply be returned. The benefit of this


< prev index next >