JavaFx swing节点中的Swing组件错误的鼠标事件

时间:2014-02-18 18:28:16

标签: javafx javafx-8

我使用Java 8对Stage中的SwingNode中的JButton进行了一次小测试。 问题:未触发右键单击,中间单击被解释为右键单击... 这是代码:

Platform.runLater(new Runnable() {

  @Override
  public void run() {


HBox hb = new HBox();

SwingNode n = new SwingNode();

JButton b = new JButton("CLICK ME!!!");
b.addMouseListener(new MouseAdapter()   {   
     public final void mousePressed(MouseEvent e) {
    boolean isLeftClick = SwingUtilities.isLeftMouseButton(e);
    boolean isRightClick = SwingUtilities.isRightMouseButton(e);
    if (isLeftClick)
       System.out.println("Left");
    if (isRightClick)
       System.out.println("Right");
        }
});  
n.setContent(b);
hb.getChildren().add(n);

Stage stage = new Stage();

Scene appScene = new Scene(hb,100, 100);

stage.setScene(appScene);


stage.show();
}
});

0 个答案:

没有答案