Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Menu bar accelerators do not work when RichTextFX control has focus #185

Closed
JFormDesigner opened this issue Sep 29, 2015 · 8 comments
Closed

Comments

@JFormDesigner
Copy link
Contributor

When the a RichTextFX control is focused, the menu bar accelerators do not work.

In Markdown Writer FX I workaround this by installing all menu bar accelarators into the RichTextFX controls. See: MarkdownEditorPane.java#L130-L132 and MainWindow.java#L302-L327

Made a little test app that demonstrates that menu bar accelarators do not work when a RichTextFX control has focus, but do work when a plain JavaFX text area has focus:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.input.KeyCombination;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import org.fxmisc.richtext.StyleClassedTextArea;

public class RichTextWithMenuBarTest extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        StyleClassedTextArea richTextArea = new StyleClassedTextArea();
        richTextArea.replaceText("RichTextFX control - Ctrl+O does not work when focused");

        TextArea textArea = new TextArea("TextArea control - Ctrl+O works when focused");

        BorderPane root = new BorderPane(richTextArea);
        root.setTop(createMenuBar());
        root.setBottom(textArea);

        Scene scene = new Scene(root, 600, 400);
        primaryStage.setScene(scene);
        primaryStage.setTitle("RichText With MenuBar Test");
        primaryStage.show();
    }

    private MenuBar createMenuBar() {
        MenuItem fileOpenItem = new MenuItem("Open");
        fileOpenItem.setAccelerator(KeyCombination.valueOf("Ctrl+O"));
        fileOpenItem.setOnAction(e -> {
            Alert alert = new Alert(Alert.AlertType.INFORMATION, "Ctrl+O pressed");
            alert.showAndWait();
        });

        Menu fileMenu = new Menu("File", null, fileOpenItem);
        return new MenuBar(fileMenu);
    }
}

Karl

@QAston
Copy link

QAston commented Sep 29, 2015

Having the same problem here, Windows, JDK 1.8.0_45

@TomasMikula
Copy link
Member

I tried your example, but I cannot reproduce the problem. The Alert dialog gets displayed regardless of which text area is focused. This is on Mac and JDK 8u60. Strangely enough, with JDK 8u40 I get the dialog displayed twice in a row, which might be the same issue as #184.

@JFormDesigner
Copy link
Contributor Author

I've noticed the problem on Windows 8.1 and JDK 8u60.

@TomasMikula
Copy link
Member

OK, I see an issue in the code.

@TomasMikula
Copy link
Member

Please, try the newest snapshot.

@QAston
Copy link

QAston commented Sep 29, 2015

The snapshot works, thanks for a very quick fix!

@JFormDesigner
Copy link
Contributor Author

Thanks. Works now in Markdown Writer FX without workaround.

@TomasMikula
Copy link
Member

I just published 0.6.10 with this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants