我在拖放操作期间使用弹出对话框。当下降发生时会弹出一个对话框,当它被解散时,事件链应该继续,并且在拖动操作结束时允许发生某些事情。如果弹出对话框是FX,那么没有问题,但如果它是Gluon,则拖动完成操作不会发生。对话框导致拖动完成事件不传播
下面是一个示例的代码:在其上的背景变为红色
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Label;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.DataFormat;
import javafx.scene.input.Dragboard;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.Background;
import javafx.scene.layout.BackgroundFill;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
import com.gluonhq.charm.glisten.mvc.View;
public class MainView extends View {
HBox root;
public MainView(String name) {
super(name);
Label source = new Label("Source");
configureDragSource(source);
Label target = new Label("Target");
configureDragTarget(target);
Label popupTarget = new Label("Popup Target");
configureDragPopupTarget(popupTarget);
root = new HBox(40, source, target, popupTarget);
setCenter(root);
}
private void configureDragSource(Label source) {
source.setOnDragDetected(e -> {
root.setBackground(new Background(new BackgroundFill(Color.RED, null, null)));
Dragboard db = source.startDragAndDrop(TransferMode.ANY);
ClipboardContent content = new ClipboardContent();
content.put(DataFormat.PLAIN_TEXT, source.getText());
db.setContent(content);
});
source.setOnDragDone(e -> root.setBackground(new Background(new BackgroundFill(null, null, null))));
}
private void configureDragTarget(Label target) {
target.setOnDragOver(e -> e.acceptTransferModes(TransferMode.ANY));
}
private void configureDragPopupTarget(Label popupTarget) {
popupTarget.setOnDragOver(e -> e.acceptTransferModes(TransferMode.ANY));
popupTarget.setOnDragDropped(e -> {
javafx.scene.control.Alert popup1 = new javafx.scene.control.Alert(AlertType.INFORMATION);
com.gluonhq.charm.glisten.control.Alert popup2 = new com.gluonhq.charm.glisten.control.Alert(AlertType.INFORMATION);
popup1.showAndWait();
});
}
}
源应被拖动。拖动操作完成后,背景应该恢复为默认值。常规放置目标什么都不做,颜色变化起作用。但是,当弹出目标时弹出对话框,当它关闭时,颜色只会改变FX对话框而不改变胶子对话框。将popup1.showAndWait();
更改为popup2
。
如果重要的是这样的应用程序类
import com.gluonhq.charm.glisten.application.MobileApplication;
public class TestApplication extends MobileApplication {
@Override
public void init() {
addViewFactory(HOME_VIEW,() -> new MainView(HOME_VIEW));
}
public static void main(String[] args) {
launch(args);
}
}
,这是gradle这个构建文件:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.3.5'
}
}
apply plugin: 'org.javafxports.jfxmobile'
apply plugin: 'eclipse'
jar {
manifest {
attributes 'Main-Class': 'com.test.TestApplication'
}
}
jfxmobile {
downConfig {
version = '3.3.0'
plugins 'display', 'lifecycle', 'statusbar', 'storage'
}
android {
compileSdkVersion = 19
// manifest = 'src/android/AndroidManifest.xml'
}
ios {
infoPList = file('src/ios/Default-Info.plist')
forceLinkClasses = [
'com.gluonhq.**.*',
'javax.annotations.**.*',
'javax.inject.**.*',
'javax.json.**.*',
'org.glassfish.json.**.*'
]
}
}
eclipse {
classpath {
downloadJavadoc = true
downloadSources = true
}
}
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'com.test.TestApplication'
dependencies {
compile 'com.gluonhq:charm:4.3.5'
}
task wrapper(type: Wrapper) {
gradleVersion = '4.2'
}
也发生在compile 'com.gluonhq:charm:4.3.7'
和4.4.0。
在Java 8 b141上运行。为什么会发生?这是一个错误?
在Dialog javadoc页面上,BTW命令行'dialog.setContent(new Label(“只是一个普通对话框,简单而简单”);'缺少'''''。 – Mark
当您在桌面上使用'popup2'运行时,您是否看到NPE? –
@JoséPereda号我还在事件处理程序中加入了try catch,并且没有发现任何东西。我应该看一个特定的地方吗? – Mark