JDK-8088471 : Alt-Gr characters (like '@') cannot be entered in any JTextComponent embedded in a SwingNode
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8,9
  • Priority: P3
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2014-12-23
  • Updated: 2018-09-05
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Related Reports
Relates :  
Description
Any characters being produced by pressing Alt-Gr and a letter key (namely '@', '���' and '��') are not entered in a JTextComponent-derived Swing text field (like JTextComponent, JPasswordField, JTextArea, ...).


Code reproducing the behaviour:

{code}
package de.shd.basis.javafxui;

import javax.swing.JTextField;
import javax.swing.SwingUtilities;

import javafx.application.Application;
import javafx.embed.swing.SwingNode;
import javafx.scene.Scene;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

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

   @Override
   public void start(Stage stage)
   {
      final SwingNode swingNode = new SwingNode();
      createAndSetSwingContent(swingNode);
      StackPane pane = new StackPane();
      pane.getChildren().add(swingNode);
      stage.setScene(new Scene(pane, 100, 50));
      stage.show();
   }

   private void createAndSetSwingContent(final SwingNode swingNode)
   {
      SwingUtilities.invokeLater(
            () -> {
               JTextField text = new JTextField();
               swingNode.setContent(text);
            }
      );
   }
}
{code}

Comments
Alt-Gr character is not inputted in normal swing textfield too. Following testcase, trying to enter ctrl+atl+e to enter "euro" character does not work. import javax.swing.*; public class JTextFieldTest { public static void main(String[] args) { SwingUtilities.invokeLater(() -> { JFrame frame = new JFrame(); JTextField field = new JTextField(20); frame.add(field); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }); } }
30-08-2017

9-client-defer-candidate: There is no resources to fix it in jdk9.
15-08-2016

This is the sequence of KeyEvents received by SwingNode.SwingKeyEventHandler.handle(event) (or its AltSwingNode subclass in my test) when pressing Alt-Gr+�� to get an @: 1 event = KeyEvent [source = AltSwingNode@5e263a49, target = AltSwingNode@5e263a49, eventType = KEY_PRESSED, consumed = false, character = ���, text = , code = CONTROL, controlDown, shortcutDown] 2 event = KeyEvent [source = AltSwingNode@5e263a49, target = AltSwingNode@5e263a49, eventType = KEY_PRESSED, consumed = false, character = ���, text = , code = ALT_GRAPH, controlDown, altDown, shortcutDown] 3 event = KeyEvent [source = AltSwingNode@5e263a49, target = AltSwingNode@5e263a49, eventType = KEY_PRESSED, consumed = false, character = ���, text = ��, code = DIGIT0, controlDown, altDown, shortcutDown] 4 event = KeyEvent [source = AltSwingNode@5e263a49, target = AltSwingNode@5e263a49, eventType = KEY_TYPED, consumed = false, character = @, text = , code = UNDEFINED, controlDown, altDown, shortcutDown] 5 event = KeyEvent [source = AltSwingNode@5e263a49, target = AltSwingNode@5e263a49, eventType = KEY_RELEASED, consumed = false, character = ���, text = , code = CONTROL, altDown] 6 event = KeyEvent [source = AltSwingNode@5e263a49, target = AltSwingNode@5e263a49, eventType = KEY_RELEASED, consumed = false, character = ���, text = , code = ALT_GRAPH] 7 event = KeyEvent [source = AltSwingNode@5e263a49, target = AltSwingNode@5e263a49, eventType = KEY_RELEASED, consumed = false, character = ���, text = ��, code = DIGIT0] On event 4, I would think there should be no modifier. Subclassing SwingNode and overriding the SwingKeyEventHandler.handle(event) to issue a KEY_TYPED event for @ with a swingModifiers = 0 when ALT_GRAPH is pressed should do it for now?
04-02-2015

Anton: can you comment on whether a fix would be feasible for 8u60?
08-01-2015

We are embedding panels of a major Swing application in a JavaFX application and are heavily concerned with this issue. We would appreciate a fix before Java 9.
08-01-2015

In that case, it seems this is not a duplicate bug, so I will reopen it.
23-12-2014

@Kevin Rushforth: In a TextField with a Greek Keyboard Layout I can use the AltGr key to type ���, ��, �� etc. Using a US KL the AltGr doesn't work. In a JTextComponent the AltGr key doesn't work neither with a Greek KL nor with a US KL
23-12-2014

This is a duplicate of RT-39464. The fact that it is also hitting SwingNode and not just TextField suggests that the bug is either in Glass or in the scene graph code that translates keyboard input to key events.
23-12-2014