Javafx 2 javafx拖放默认图标
我想在按下鼠标的同时用线连接两个形状。 正如doc所说,我不能使用按下的拖拽发布模型来实现这一点,所以应该使用拖放方法——一切看起来都正常,但如何禁用默认图标,即允许在目标上放置拖放内容?在mouseMove上我画了一条线,我不想要这些默认图标 我包括一个简单的程序来显示它-只要运行我尝试拖动一个圆圈到另一个Javafx 2 javafx拖放默认图标,javafx-2,Javafx 2,我想在按下鼠标的同时用线连接两个形状。 正如doc所说,我不能使用按下的拖拽发布模型来实现这一点,所以应该使用拖放方法——一切看起来都正常,但如何禁用默认图标,即允许在目标上放置拖放内容?在mouseMove上我画了一条线,我不想要这些默认图标 我包括一个简单的程序来显示它-只要运行我尝试拖动一个圆圈到另一个 /* * To change this template, choose Tools | Templates * and open the template in the editor.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package onreleased;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.input.*;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
/**
*
* @author mmk
*/
public class DaDIcons extends Application {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
final Label label = new Label("started");
label.setLayoutY(100);
Pane pane = new Pane();
Circle red = createCircle(40, 40, 30, Color.RED, label);
Circle blue = createCircle(160, 40, 30, Color.BLUE, label);
pane.setOnDragOver(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent event) {
System.out.println("foo");
}
});
pane.getChildren().addAll(red, blue, label);
primaryStage.setScene(new Scene(pane, 300, 250));
primaryStage.show();
}
private Circle createCircle(double x, double y, double r, final Color color, final Label statusLabel) {
final Circle circle = new Circle(x, y, r);
circle.setFill(color);
circle.setOnDragOver(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent event) {
statusLabel.setText(color.toString() + " over");
System.out.println("foo");
if (event.getGestureSource() != circle) {
event.acceptTransferModes(TransferMode.ANY);
}
}
});
circle.setOnDragDropped(new EventHandler<DragEvent>() {
@Override
public void handle(DragEvent arg0) {
statusLabel.setText(color.toString() + " dropped");
}
});
circle.setOnDragDetected(new EventHandler<MouseEvent>() {
@Override
public void handle(MouseEvent arg0) {
circle.startDragAndDrop(TransferMode.ANY);
Dragboard db = circle.startDragAndDrop(TransferMode.ANY);
/*
* Put a string on a dragboard
*/
ClipboardContent content = new ClipboardContent();
content.putString("foo");
db.setContent(content);
statusLabel.setText(color.toString() + " xxxxxxxxxxxxxxxxxxxxxxx");
}
});
circle.setOnDragEntered(null);
return circle;
}
}
您可以在拖放操作时管理光标。
在circle.setOnDragDetected操作集circle.setCursor.NONE上;和
在circle.setOnDragDrop操作上,将其反转为circle.setCursorCursor.DEFAULT;。
不显示光标图标,您可以在d-n-drop时在鼠标坐标处显示图像。那么它是如何工作的呢?它是否抛出异常?禁用光标不符合您的需要?答案需要更多解释?设置光标没有任何效果。在每个拖动事件上都没有-它仍然是默认值。同时我发现我很可能在父节点上使用onMousePressed,我将检查子节点是否被按下/释放/对不起,要么这个问题有误导性,要么我误解了。在我的项目中,我也使用了拖放。仪表板项目是带有图像的按钮,图像被放入仪表板网格中。拖动时,将禁用光标,并使用imageview显示被拖动按钮的图像。因此,Curser.NONE可以在不同的用途和环境下工作。