1
我想连接2个形状与线,而鼠标按下。 由于文档说我不能使用按下拖动释放模型来做到这一点,所以应该使用拖放方法 - 一切看起来都不错,但是如何禁用默认图标,该图标表示允许拖放内容放置目标?在mouseMove上画线,我不想要这些默认图标。javafx拖放默认图标
我包括简单的程序显示它 - 只要运行我尝试拖一圈到其他。
/*
* 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;
}
}
对不起,但它不起作用。 – 2012-04-16 13:49:19
那它怎么没用?它抛出异常吗?禁用光标不符合您的需求?答案需要更多解释? – 2012-04-16 14:30:37
每个拖动事件都没有设置Cursor.NONE的效果 - 它仍然是默认值。我发现与此同时http://javafx-jira.kenai.com/browse/RT-20326所以propably我使用onMousePressed在父节点,我会检查子节点被按下/释放;/ – 2012-04-16 14:52:46