使用 Gluon Charm 警报的问题

Problems using Gluon Charm's Alert

我了解 JavaFX 的警报还不能用于移动应用程序。但是 Gluon Charm Alert 呢?

我已经定义了一个 Gluon Mobile MultiView FXML 项目。我已经更新了 gradle 项目的依赖项以包含 charm-2.2.0.jar,因此 Gluon Charm Alert class 可用。为了使用它,您还需要访问 javafx.scene.control.Alert.AlertType.

我似乎没有编译时访问上述 AlertType class。

我在 Mac 和 OS X 10.11.14 上使用带有最新 Gluon/Gradle 插件的 NetBeans 8.1。是否有我必须定义的额外配置依赖项?

在此先感谢您的帮助。

这是我的 build.gradle 文件。

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'org.javafxports:jfxmobile-plugin:1.0.8'
    }
}

apply plugin: 'org.javafxports.jfxmobile'

repositories {
    jcenter()
    maven {
        url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
    }
}

mainClassName = 'com.capitals.Capitals'

dependencies {
    compile 'com.gluonhq:charm:2.2.0'
    androidRuntime 'com.gluonhq:charm-android:2.2.0'
    iosRuntime 'com.gluonhq:charm-ios:2.2.0'
    desktopRuntime 'com.gluonhq:charm-desktop:2.2.0'
}

jfxmobile {
    android {
        manifest = 'src/android/AndroidManifest.xml'
    }
    ios {
        infoPList = file('src/ios/Default-Info.plist')
        forceLinkClasses = [
                'com.asgteach.capitals.**.*',
                'com.gluonhq.**.*',
                'io.datafx.**.*',
                'javax.annotations.**.*',
                'javax.inject.**.*',
                'javax.json.**.*',
                'org.glassfish.json.**.*'
        ]
    }
}

您可以访问 JavaFX Alert.AlertType class,无需添加任何依赖项。

确保您使用的是最新版本的 jfxmobile 插件 (1.0.8)。

这适用于桌面和移动设备:

import com.gluonhq.charm.glisten.control.Alert;
import com.gluonhq.charm.glisten.control.AppBar;
import com.gluonhq.charm.glisten.mvc.View;
import com.gluonhq.charm.glisten.visual.MaterialDesignIcon;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;

public class BasicView extends View {
  public BasicView(String name) {
    super(name);
    Button button = new Button("Show alert");
    button.setOnAction(e -> {
        Alert alert = new Alert(AlertType.INFORMATION, "This is an Alert!");
        alert.showAndWait();
    });
    setCenter(new StackPane(button));
  }
}

如果您不是这种情况,post 您的 build.gradle 以及您可能遇到的任何例外情况。