apache / apache/netbeans

Key Events Bypass spawned JFrame in NetBeans Module

Open
#6,792 1 comment 0 reactions 0 assignees View on GitHub
kind:bug needs:triage UI
Dominant language
Java
Stars
3.1k
Forks
935
Avg merge
2d 3h
Merged PRs (30d)
17

Description

### Apache NetBeans version

Apache NetBeans 19

### What happened

I have a NetBeans module that includes a JFrame. This JFrame is capable of being minimized, maximized, and resized like any other non-modal window. When focusing on a widget within the JFrame instance that doesn't consume a key event, the event bypasses the frame and is subsequently captured by the NetBeans main window, provided that the pressed keys are registered in the keymap.

For example, if you're in the text area of a file and press the "Delete" key, the next character at the caret's position will be removed. Similarly, if the focus is on a file node in the project view, the file will undergo the remove action.

Expected behaviour: The key event should not be passed to the parent unless explicitly programmed for it.

### How to reproduce

Attached is a minimal reproducible example [moduletest.zip](https://github.com/apache/netbeans/files/13551985/moduletest.zip), NetBeans module, that creates an action just below the File menu. This just spawns a frame with multiple widgets that don't do anything, among the widgets, there is also a JTextField.

1. Run the NetBeans module
2. Open any file with some text and position the caret in the middle of a word
3. Trigger the `Spawn Second Frame` action
4. The `SpawnableFrame` will pop up with the focus on the `JButton`
5. Press the key "Delete".
- You will notice the text in the file of the main window gets edited.
6. Press "Ctrl + Z"
- You will notice how the `undo` action also takes effect.

For reference, please also find attached a minimal maven project ([minimalmavenproject.zip](https://github.com/apache/netbeans/files/13551999/minimalmavenproject.zip)) only using swing and registering the `Delete` action in the keybindings that mimic the same behaviour. In this example, the issue does no occur.

### Did this work correctly in an earlier version?

No / Don't know

### Operating System

Windows 11

### JDK

19.0.2

### Apache NetBeans packaging

Apache NetBeans binary zip

### Anything else

Note:
This behaviour does not occur if the previously selected (focused) widget in the SpawnableFrame is a widget that typically consumes the key event, such as the JTextField. Therefore, performing the following steps will not lead to the issue:

Repeating the same four steps mentioned earlier:
4. Set the focus on the JTextField.
5. Move the focus to the JButton or any of the other widgets.
7. Press the Delete key again.
- You will observe that the key event no longer bypasses the SpawnableFrame.

### Are you willing to submit a pull request?

No

Contributor guide

Open the contributing guide

Research direction

Start by running the attached moduletest.zip and reproduce the Delete-key behavior from the SpawnableFrame opened by the “Spawn Second Frame” action. Compare it with minimalmavenproject.zip, where the issue does not occur, and trace the relevant NetBeans keymap and spawned-frame behavior. Done means unconsumed key events in the spawned JFrame no longer affect the main window.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
40/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.