JavaFX8: How to create listener for selection of row in Tableview?

The selectedItem in the selection model is an observable property, so you should be able to achieve this with: tableview1.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) -> { if (newSelection != null) { tableview2.getSelectionModel().clearSelection(); } }); tableview2.getSelectionModel().selectedItemProperty().addListener((obs, oldSelection, newSelection) -> { if (newSelection != null) { tableview1.getSelectionModel().clearSelection(); } });

JavaFX TableView text alignment

Alignment of all table columns: Starting from JavaFX-8, you can use newly defined CSS selector table-column, #my-table .table-column { -fx-alignment: CENTER-RIGHT; } For JavaFX-2, To achieve this define a CSS selector: #my-table .table-cell { -fx-alignment: CENTER-RIGHT; /* The rest is from caspian.css */ -fx-skin: “com.sun.javafx.scene.control.skin.TableCellSkin”; -fx-padding: 0.166667em; /* 2px, plus border adds 1px */ -fx-background-color: … Read more

Changing background color of selected cell?

Changing the property selectedBackgroundView is correct and the simplest way. I use the following code to change the selection color: // set selection color UIView *myBackView = [[UIView alloc] initWithFrame:cell.frame]; myBackView.backgroundColor = [UIColor colorWithRed:1 green:1 blue:0.75 alpha:1]; cell.selectedBackgroundView = myBackView; [myBackView release];

Scroll to top of UITableView by tapping status bar

You get this for free, but you should check that the scrollsToTop attribute of your UITableView is YES. When this does NOT work is when you have a UIScrollView (or descendant class like UITextView) object embedded inside another UIScrollView class (like UITableView). In this case, set scrollsToTop on the embedded UIScrollView class to NO. Then … Read more

Set collectionView size. (sizeForItemAtIndexPath function is not working) Swift 3

First, don’t forget to extends from UICollectionViewDelegateFlowLayout delegate. For single collectionview display logic : func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { let width = ((collectionView.frame.width – 15) / 2) // 15 because of paddings print(“cell width : \(width)”) return CGSize(width: width, height: 200) } And important point in storyboard … Read more

Detect doubleclick on row of TableView JavaFX

TableView<MyType> table = new TableView<>(); //… table.setRowFactory( tv -> { TableRow<MyType> row = new TableRow<>(); row.setOnMouseClicked(event -> { if (event.getClickCount() == 2 && (! row.isEmpty()) ) { MyType rowData = row.getItem(); System.out.println(rowData); } }); return row ; }); Here is a complete working example: import java.util.Random; import java.util.function.Function; import javafx.application.Application; import javafx.beans.property.IntegerProperty; import javafx.beans.property.SimpleIntegerProperty; import … Read more

JavaFX 2.1 TableView refresh items

Since JavaFX 8u60 you can use(assuming tableView is an instance of TableView class): tableView.refresh(); From the documentation: Calling refresh() forces the TableView control to recreate and repopulate the cells necessary to populate the visual bounds of the control. In other words, this forces the TableView to update what it is showing to the user. This … Read more