Background
Save a file using the JavaFX save dialog the continue using the application. This is using JavaFX 16, Java 16, and Linux/Xfce, but the issue is present in previous versions.
Problem
After choosing to overwrite an existing file, the application is no longer fully responsive: the caret disappears, menu is no longer accessible, etc. Replicate:
- Create a new file (e.g.,
touch $HOME/test.txt
). - Run the code.
- Click File.
- Click Save As.
- Double-click
test.txt
. - Confirm replacing the file.
- Click File.
Expected: File menu opens, caret remains visible.
Actual: File menu staunchly rebels, caret goes on vacation.
Jankiest workaround: Relinquish application focus, then return, shake head in confusion (optional).
Code
SSCCE:
import javafx.event.*; import javafx.scene.*; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.*; public final class MainApp extends Application { public static void main( final String[] args ) { launch( args ); } @Override public void start( final Stage stage ) { final var root = new Group(); final var scene = new Scene( root, 400, 400 ); final var pane = new BorderPane(); final var menuBar = new MenuBar(); final var menu = new Menu( "File" ); final var file = new MenuItem( "Save As" ); final var textArea = new TextArea(); file.setOnAction( e -> new FileChooser().showSaveDialog( scene.getWindow() ) ); menu.getItems().add( file ); menuBar.getMenus().add( menu ); pane.prefHeightProperty().bind( scene.heightProperty() ); pane.prefWidthProperty().bind( scene.widthProperty() ); pane.setTop( menuBar ); pane.setCenter( textArea ); root.getChildren().add( pane ); stage.setScene( scene ); stage.show(); } }
Question
How can the application be fixed? (The bug has been reported, FWIW.)
https://stackoverflow.com/questions/66979424/replacing-file-via-filechooser-dialog-pooches-application April 07, 2021 at 12:07PM
没有评论:
发表评论