Skip to content

ContextMenu click will loose focus #919

@effad

Description

@effad

Expected Behavior

When right-clicking a CodeArea with context menu (or even without one) that lives in a container that can itself have the keyboard focus, the focus should not be lost by the CodeArea.

When using a (JavaFX built-in) TextArea focus is not lost.

I presume that either the event must be consumed or CodeArea should accept focus upon right-click (it does not at the moment)

Actual Behavior

Focus is lost.

Reproducible Demo

import org.fxmisc.flowless.VirtualizedScrollPane;
import org.fxmisc.richtext.CodeArea;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TitledPane;
import javafx.stage.Stage;

public class ContextMenuFocusBug extends Application {

	private CodeArea area;

    @Override
    public void start(Stage primaryStage) {
        area = new CodeArea("Right-click me!\n");
        setupContextMenu();
    	TitledPane container = new TitledPane("Nice", new VirtualizedScrollPane<>(area));
        primaryStage.setScene(new Scene(container, 400, 500));
        primaryStage.setTitle("Losing focus on right-click");
        primaryStage.show();
    }
    
    private void setupContextMenu() {
		ContextMenu contextMenu = new ContextMenu(
			new MenuItem("Test")
		);
		contextMenu.setStyle("-fx-font-family: 'Droid Sans';");	// hack to get regular styling in context menu
		area.setContextMenu(contextMenu);		
	}

    public static void main(String[] args) {
        launch(args);
    }
}

Environment info:

  • RichTextFX Version: 0.10.4
  • Operating System: Linux (Fedora 31)
  • Java version: 13

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions