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);
}
}
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);
}
}
- duplicates
-
JDK-8199498 Custom cursor not supported in SwingNode
- Closed
- relates to
-
JDK-8087664 Changing Cursor of content inside JFXPanel to Cursor.CLOSED_HAND or Cursor.OPEN_HAND doesn't work
- Open