Colouring table row in JavaFX

Use a row factory, instead of a cell factory, if you want to change the color of the whole row: tv_mm_view.setRowFactory(tv -> new TableRow<FaDeal>() { @Override public void updateItem(FaDeal item, boolean empty) { super.updateItem(item, empty) ; if (item == null) { setStyle(“”); } else if (item.getInstrumentId().equals(“1070”)) { setStyle(“-fx-background-color: tomato;”); } else { setStyle(“”); } } … Read more

Copiable Label/TextField/LabeledText in JavaFX

You can create a TextField without the border and background color with css: import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.TextField; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class CopyableLabel extends Application { @Override public void start(Stage primaryStage) { TextField copyable = new TextField(“Copy this”); copyable.setEditable(false); copyable.getStyleClass().add(“copyable-label”); TextField tf2 = new TextField(); VBox root = new VBox(); root.getChildren().addAll(copyable, tf2); … Read more

JavaFX table- how to add components?

Issues with your Implementation You can embed JavaFX components in Swing applications (by placing the JavaFX component in a JFXPanel). But you can’t embed a Swing component in JavaFX (unless you are using JavaFX 8+). JavaFX has it’s own button implementation anyway, so there is no reason to embed a javax.swing.JButton on a JavaFX scene, … Read more

One controller to 2 fxmls (JavaFX)

Yes, you can do this. Although, it can be done, I do not recommend this approach. Don’t place a fx:controller attribute in either FXML. Create a new controller and set the same controller into separate FXMLLoader instances. CustomerDialogController dialogController = new CustomerDialogController(param1, param2); FXMLLoader summaryloader = new FXMLLoader( getClass().getResource( “customerSummary.fxml” ) ); summaryLoader.setController(dialogController); Pane summaryPane … Read more

TableView: adjust number of visible rows

Changing tableview’s height and removing “empty” rows are two different things. Be specific. For removing rows see this tutorial. For changing height, first set the fixedCellSizeProperty of the table view then use it in binding: table.setFixedCellSize(25); table.prefHeightProperty().bind(Bindings.size(table.getItems()).multiply(table.getFixedCellSize()).add(30)); Adding 30px is for tableview’s header.

JavaFX 2 TableView : different cell factory depending on the data inside the cell

Here is a table displaying pairs of Strings and Objects of various types. A custom cell factory is used to handle display of different object types (by performing an instanceof check on the object’s type and rendering the appropriate text or graphic). import javafx.application.*; import javafx.beans.property.ReadOnlyObjectWrapper; import javafx.beans.value.ObservableValue; import javafx.collections.*; import javafx.scene.Scene; import javafx.scene.control.*; import … Read more

Adding a CheckBox column to an existing TableView

Summary: As noted here, this is likely a bug; steps to avoid the pitfall include these: Verify that the data model exports properties correctly, as shown here. Critically examine the value of replacing PropertyValueFactory with an explicit Callback, when possible, as outlined here, here, here, here and here. The problem is that CheckBoxTableCell can’t find … Read more