How to add CheckBox’s to a TableView in JavaFX

Uses javafx.scene.control.cell.CheckBoxTableCell<S,T> and the work’s done ! ObservableList< TableColumn< RSSReader, ? >> columns = _rssStreamsView.getColumns(); […] TableColumn< RSSReader, Boolean > loadedColumn = new TableColumn<>( “Loaded” ); loadedColumn.setCellValueFactory( new Callback<CellDataFeatures<RSSReader,Boolean>,ObservableValue<Boolean>>(){ @Override public ObservableValue<Boolean> call( CellDataFeatures<RSSReader,Boolean> p ){ return p.getValue().getCompleted(); }}); loadedColumn.setCellFactory( new Callback<TableColumn<RSSReader,Boolean>,TableCell<RSSReader,Boolean>>(){ @Override public TableCell<RSSReader,Boolean> call( TableColumn<RSSReader,Boolean> p ){ return new CheckBoxTableCell<>(); }}); […] columns.add( … Read more

JavaFX FileChooser: how to set file filters?

You could do: FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter(“TXT files (*.txt)”, “*.txt”); chooser.getExtensionFilters().add(extFilter); Here is a simple example: public class ExtensionFilterExample extends Application { public static void main(String[] args) { launch(args); } @Override public void start(final Stage primaryStage) { primaryStage.setTitle(“Extension Filter Example”); final Label fileLabel = new Label(); Button btn = new Button(“Open FileChooser”); btn.setOnAction(new EventHandler<ActionEvent>() … Read more

Updating UI from different threads in JavaFX

Not sure if I completely understand, but I think this may help. Using Platform.runLater(…) is an appropriate approach for this. The trick to avoiding flooding the FX Application Thread is to use an Atomic variable to store the value you’re interested in. In the Platform.runLater method, retrieve it and set it to a sentinel value. … Read more

Make portion of a text bold in a JavaFx Label or Text

It is possible to use TextFlow container from JavaFX8. Then you can easily add differently styled Text nodes inside it. TextFlow flow = new TextFlow(); Text text1=new Text(“Some Text”); text1.setStyle(“-fx-font-weight: bold”); Text text2=new Text(“Some Text”); text2.setStyle(“-fx-font-weight: regular”); flow.getChildren().addAll(text1, text2); TextFlow container will automatically wrap content Text nodes.

How to create a modal window in JavaFX 2.1

In my opinion this is not good solution, because parent window is all time active. For example if You want open window as modal after click button… private void clickShow(ActionEvent event) { Stage stage = new Stage(); Parent root = FXMLLoader.load( YourClassController.class.getResource(“YourClass.fxml”)); stage.setScene(new Scene(root)); stage.setTitle(“My modal window”); stage.initModality(Modality.WINDOW_MODAL); stage.initOwner( ((Node)event.getSource()).getScene().getWindow() ); stage.show(); } Now Your … Read more

Setting a cookie using JavaFX’s WebEngine/WebView

I have managed to solve this issue with the help of Vasiliy Baranov from Oracle. Vasiliy wrote to me: Try putting the cookie into java.net.CookieHandler.getDefault() after the WebView is instantiated for the first time and before the call to WebEngine.load, e.g. as follows: WebView webView = new WebView(); URI uri = URI.create(“http://mysite.com”); Map<String, List<String>> headers … Read more