Set up a simple menu bar and a simple textarea (or anything else that can receive focus).
On a standard application one would expect that clicking some menu item such as File-->New will send the focus back to whatever had focus before, in this case, TextArea.
However upon clicking New, the menu File remains highlighted, and the text area does not have focus.
Please refer to the following code, which is also attached:
import javafx.application.Application;
import javafx.builders.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;
public class MenuFocusBugTest extends Application {
@Override
public void start(Stage stage) throws Exception {
stage.setScene(
SceneBuilder.create()
.root(BorderPaneBuilder.create()
.top(MenuBarBuilder.create()
.menus(MenuBuilder.create()
.items(MenuItemBuilder.create()
.text("New")
.onAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent actionEvent) {
}
})
.build()
)
.text("File")
.build()
)
.build()
)
.center(
new TextArea()
)
.build()
)
.build()
);
stage.setVisible(true);
}
public static void main(String[] args) {
Application.launch(MenuFocusBugTest.class, null);
}
}
On a standard application one would expect that clicking some menu item such as File-->New will send the focus back to whatever had focus before, in this case, TextArea.
However upon clicking New, the menu File remains highlighted, and the text area does not have focus.
Please refer to the following code, which is also attached:
import javafx.application.Application;
import javafx.builders.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.TextArea;
import javafx.stage.Stage;
public class MenuFocusBugTest extends Application {
@Override
public void start(Stage stage) throws Exception {
stage.setScene(
SceneBuilder.create()
.root(BorderPaneBuilder.create()
.top(MenuBarBuilder.create()
.menus(MenuBuilder.create()
.items(MenuItemBuilder.create()
.text("New")
.onAction(new EventHandler<ActionEvent>() {
public void handle(ActionEvent actionEvent) {
}
})
.build()
)
.text("File")
.build()
)
.build()
)
.center(
new TextArea()
)
.build()
)
.build()
);
stage.setVisible(true);
}
public static void main(String[] args) {
Application.launch(MenuFocusBugTest.class, null);
}
}
- relates to
-
JDK-8118345 menubar steals focus on click making it impossible to do copy paste selected text in a TextField.
- Closed