Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8128724

FXCanvas: incorrect KeyPressed/KeyReleased events is received

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P1
    • Resolution: Fixed
    • Affects Version/s: fx2.0.2
    • Fix Version/s: fx2.0.2
    • Component/s: javafx
    • Environment:

      Win7/JDK6/2.0.2 controls-scrum

      Description

      KeyEvent.code is set to UNDEFINED


      import javafx.scene.Scene;

      import javafx.embed.swt.FXCanvas;
      import javafx.event.EventHandler;
      import javafx.scene.control.Button;
      import javafx.scene.control.TextField;
      import javafx.scene.input.KeyEvent;
      import javafx.scene.layout.VBox;

      import org.eclipse.swt.SWT;
      import org.eclipse.swt.layout.FillLayout;

      import org.eclipse.swt.widgets.Display;
      import org.eclipse.swt.widgets.Shell;

      public class Main {

          private static void createScene(final FXCanvas fxPanel) {
              VBox root = new VBox();
              final Scene scene = new Scene(root);

              scene.setOnKeyPressed(new EventHandler<KeyEvent>() {
                  public void handle(KeyEvent ke) {
                      System.out.println("OnKeyPressed KeyEvent: " + ke);
                  }
              });

              scene.setOnKeyReleased(new EventHandler<KeyEvent>() {
                  public void handle(KeyEvent ke) {
                      System.out.println("OnKeyReleased KeyEvent: " + ke);
                  }
              });

              Button button = new Button("Button");

              TextField text = new TextField();

              root.getChildren().add(button);
              root.getChildren().add(text);

              fxPanel.setScene(scene);
          }

          public static void main(String[] args) {
              Display display = new Display();
              Shell shell = new Shell(display);
              shell.setSize(400, 400);
              shell.setLayout(new FillLayout());

              final FXCanvas fxPanel = new FXCanvas(shell, SWT.NONE);

              createScene(fxPanel);

              shell.open();
              while (!shell.isDisposed()) {
                  if (!display.readAndDispatch()) {
                      display.sleep();
                  }
              }
          }
      }

        Attachments

          Activity

            People

            Assignee:
            snorthov Steve Northover (Inactive)
            Reporter:
            ogb Oleg Barbashov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported: