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

[SwingNode]:swing component in swingnode cannot set customer cursor

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u5
    • javafx
    • None

      we cannot hide or set the customer cursor when insert the awt component to swingnode

      swingnode exam:
      public class TestSwingNodeAwtCustomerCursor extends Application {
          @Override
          public void start(Stage primaryStage) throws Exception {
              BorderPane borderPane = new BorderPane();
              SwingNode swingNode = new SwingNode();
              createSwingContent(swingNode);
              borderPane.setCenter(swingNode);

              Scene scene = new Scene(borderPane, 1200, 800);
              primaryStage.setScene(scene);
              primaryStage.show();
          }

          private void createSwingContent(final SwingNode swingNode) {
              SwingUtilities.invokeLater(new Runnable() {
                  @Override
                  public void run() {
                      JPanel jPanel = new JPanel();
                      BorderLayout borderLayout = new BorderLayout();
                      jPanel.setLayout(borderLayout);
                      JTextArea textArea = new JTextArea(200, 300);
                      jPanel.add(textArea);


                      int[] pixels = new int[16 * 16];
                      Image image = Toolkit.getDefaultToolkit()
                              .createImage(
                                      new java.awt.image.MemoryImageSource(16, 16,
                                              pixels, 0, 16));
                      //invalid
                      textArea.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(
                              image, new Point(0, 0), "blank cursor"));

                      //valid
                     // textArea.setCursor(java.awt.Cursor.getDefaultCursor());

                      //valid
                    // textArea.setCursor(java.awt.Cursor.getPredefinedCursor(java.awt.Cursor.CROSSHAIR_CURSOR));
                      swingNode.setContent(jPanel);
                  }
              });
          }

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

      normal awt exam:
      public class TestAwtCustomerCursor {
          public static void main(String[] args) {
              createWin();
          }

          static void createWin() {
              JFrame frame = new JFrame();
              frame.setVisible(true);
              frame.setLayout(new BorderLayout());
              frame.setSize(600, 500);
              frame.setTitle("abc");

              JPanel jPanel = new JPanel();
              jPanel.setSize(400, 400);
              jPanel.setLayout(new BorderLayout());
              JTextArea textArea = new JTextArea("oooooooo", 200, 300);

              jPanel.add(textArea);
              frame.add(jPanel);

              frame.setLocation(500, 200);
              int[] pixels = new int[16 * 16];
              Image image = Toolkit.getDefaultToolkit()
                      .createImage(
                              new java.awt.image.MemoryImageSource(16, 16,
                                      pixels, 0, 16));

              textArea.setCursor(Toolkit.getDefaultToolkit().createCustomCursor(
                      image, new Point(0, 0), "blank cursor"));

              frame.setVisible(true);

          }
      }

            psadhukhan Prasanta Sadhukhan
            hgreenjfx Herry Green (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Imported: