How do I pick up the Enter Key being pressed in JavaFX2?

I’m assuming you want this to happen when the user presses enter only while the TextField has focus. You’ll want use KeyEvent out of javafx.scene.input package and do something like this: field.setOnKeyPressed(new EventHandler<KeyEvent>() { @Override public void handle(KeyEvent ke) { if (ke.getCode().equals(KeyCode.ENTER)) { doSomething(); } } }); Using lambda: field.setOnKeyPressed( event -> { if( event.getCode() … 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

FXML full reference?

FXML Reference Introduction to FXML describes the syntax and usage patterns of the markup and is important to study when learning FXML. It does not define all elements usable in FXML. There will never be a full reference (nor xml schema) for FXML as it works by reflecting on Java classes in the classpath and … Read more

Update JavaFX UI from another thread

I’m running into a similar issue, as far as I can tell you have to deal with the error handling yourself. My solution is to update the UI via a method call: Something like: try { //blah… } catch (Exception e) { reportAndLogException(e); } … public void reportAndLogException(final Throwable t) { Platform.runLater(new Runnable() { @Override … Read more

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