Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Uses <a href="http://docs.oracle.com/javafx/2/api/javafx/scene/control/cell/CheckBoxTableCell.html" rel="nofollow noreferrer"><code>javafx.scene.control.cell.CheckBoxTableCell&lt;S,T&gt;</code></a> and the work's done !</p> <pre><code> ObservableList&lt; TableColumn&lt; RSSReader, ? &gt;&gt; columns = _rssStreamsView.getColumns(); [...] TableColumn&lt; RSSReader, Boolean &gt; loadedColumn = new TableColumn&lt;&gt;( "Loaded" ); loadedColumn.setCellValueFactory( new Callback&lt;CellDataFeatures&lt;RSSReader,Boolean&gt;,ObservableValue&lt;Boolean&gt;&gt;(){ @Override public ObservableValue&lt;Boolean&gt; call( CellDataFeatures&lt;RSSReader,Boolean&gt; p ){ return p.getValue().getCompleted(); }}); loadedColumn.setCellFactory( new Callback&lt;TableColumn&lt;RSSReader,Boolean&gt;,TableCell&lt;RSSReader,Boolean&gt;&gt;(){ @Override public TableCell&lt;RSSReader,Boolean&gt; call( TableColumn&lt;RSSReader,Boolean&gt; p ){ return new CheckBoxTableCell&lt;&gt;(); }}); [...] columns.add( loadedColumn ); </code></pre> <p><strong>UPDATE:</strong> same code using <a href="http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html" rel="nofollow noreferrer">Java 8 lambda expressions</a></p> <pre><code> ObservableList&lt; TableColumn&lt; RSSReader, ? &gt;&gt; columns = _rssStreamsView.getColumns(); [...] TableColumn&lt; RSSReader, Boolean &gt; loadedColumn = new TableColumn&lt;&gt;( "Loaded" ); loadedColumn.setCellValueFactory( f -&gt; f.getValue().getCompleted()); loadedColumn.setCellFactory( tc -&gt; new CheckBoxTableCell&lt;&gt;()); [...] columns.add( loadedColumn ); </code></pre> <p>Lines count is divided by two! (16 ==> 8)</p> <p><strong>UPDATE:</strong> same code using <a href="http://openjdk.java.net/jeps/286" rel="nofollow noreferrer">Java 10 "var" contextual word</a></p> <pre><code> var columns = _rssStreamsView.getColumns(); [...] var loadedColumn = new TableColumn&lt;RSSReader, Boolean&gt;( "Loaded" ); loadedColumn.setCellValueFactory( f -&gt; f.getValue().getCompleted()); loadedColumn.setCellFactory( tc -&gt; new CheckBoxTableCell&lt;&gt;()); [...] columns.add( loadedColumn ); </code></pre> <p><strong>EDIT to add full functional editable example (Java 8)</strong></p> <pre><code>public class Os { private final StringProperty name = new SimpleStringProperty(); private final BooleanProperty delete = new SimpleBooleanProperty(); public Os( String nm, boolean del ) { name .set( nm ); delete.set( del ); } public StringProperty nameProperty () { return name; } public BooleanProperty deleteProperty() { return delete; } } public class FxEditableCheckBox extends Application { @Override public void start( Stage stage ) throws Exception { final TableView&lt;Os&gt; view = new TableView&lt;&gt;(); final ObservableList&lt;TableColumn&lt;Os, ?&gt;&gt; columns = view.getColumns(); final TableColumn&lt;Os, Boolean&gt; nameColumn = new TableColumn&lt;&gt;( "Name" ); nameColumn.setCellValueFactory( new PropertyValueFactory&lt;&gt;( "name" )); columns.add( nameColumn ); final TableColumn&lt;Os, Boolean&gt; loadedColumn = new TableColumn&lt;&gt;( "Delete" ); loadedColumn.setCellValueFactory( new PropertyValueFactory&lt;&gt;( "delete" )); loadedColumn.setCellFactory( tc -&gt; new CheckBoxTableCell&lt;&gt;()); columns.add( loadedColumn ); final ObservableList&lt;Os&gt; items = FXCollections.observableArrayList( new Os( "Microsoft Windows 3.1" , true ), new Os( "Microsoft Windows 3.11" , true ), new Os( "Microsoft Windows 95" , true ), new Os( "Microsoft Windows NT 3.51", true ), new Os( "Microsoft Windows NT 4" , true ), new Os( "Microsoft Windows 2000" , true ), new Os( "Microsoft Windows Vista" , true ), new Os( "Microsoft Windows Seven" , false ), new Os( "Linux all versions :-)" , false )); view.setItems( items ); view.setEditable( true ); final Button delBtn = new Button( "Delete" ); delBtn.setMaxWidth( Double.MAX_VALUE ); delBtn.setOnAction( e -&gt; { final Set&lt;Os&gt; del = new HashSet&lt;&gt;(); for( final Os os : view.getItems()) { if( os.deleteProperty().get()) { del.add( os ); } } view.getItems().removeAll( del ); }); stage.setScene( new Scene( new BorderPane( view, null, null, delBtn, null ))); BorderPane.setAlignment( delBtn, Pos.CENTER ); stage.show(); } public static void main( String[] args ) { launch( args ); } } </code></pre> <p><strong>EDIT to add full functional editable example (Java 10)</strong></p> <pre><code>public class Os { private final StringProperty name = new SimpleStringProperty(); private final BooleanProperty delete = new SimpleBooleanProperty(); public Os( String nm, boolean del ) { name .set( nm ); delete.set( del ); } public StringProperty nameProperty () { return name; } public BooleanProperty deleteProperty() { return delete; } } public class FxEditableCheckBoxJava10 extends Application { @Override public void start( Stage stage ) throws Exception { final var view = new TableView&lt;Os&gt;(); final var columns = view.getColumns(); final var nameColumn = new TableColumn&lt;Os, Boolean&gt;( "Name" ); nameColumn.setCellValueFactory( new PropertyValueFactory&lt;&gt;( "name" )); columns.add( nameColumn ); final var loadedColumn = new TableColumn&lt;Os, Boolean&gt;( "Delete" ); loadedColumn.setCellValueFactory( new PropertyValueFactory&lt;&gt;( "delete" )); loadedColumn.setCellFactory( tc -&gt; new CheckBoxTableCell&lt;&gt;()); columns.add( loadedColumn ); final var items = FXCollections.observableArrayList( new Os( "Microsoft Windows 3.1" , true ), new Os( "Microsoft Windows 3.11" , true ), new Os( "Microsoft Windows 95" , true ), new Os( "Microsoft Windows NT 3.51", true ), new Os( "Microsoft Windows NT 4" , true ), new Os( "Microsoft Windows 2000" , true ), new Os( "Microsoft Windows Vista" , true ), new Os( "Microsoft Windows Seven" , false ), new Os( "Linux all versions :-)" , false )); view.setItems( items ); view.setEditable( true ); final var delBtn = new Button( "Delete" ); delBtn.setMaxWidth( Double.MAX_VALUE ); delBtn.setOnAction( e -&gt; { final var del = new HashSet&lt;Os&gt;(); for( final var os : view.getItems()) { if( os.deleteProperty().get()) { del.add( os ); } } view.getItems().removeAll( del ); }); stage.setScene( new Scene( new BorderPane( view, null, null, delBtn, null ))); BorderPane.setAlignment( delBtn, Pos.CENTER ); stage.show(); } public static void main( String[] args ) { launch( args ); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload