0

I understand that JavaFX's Alert cannot be used yet with mobile apps. But what about the Gluon Charm Alert?

I have defined a Gluon Mobile MultiView FXML project. I've updated the gradle project's dependencies to include charm-2.2.0.jar, so the Gluon Charm Alert class is available. In order to use it, you also need access to javafx.scene.control.Alert.AlertType.

I don't seem to have compile-time access to the above AlertType class.

I'm using NetBeans 8.1 with the most recent Gluon/Gradle plug-in on a Mac with OS X 10.11.14. Is there an additional configuation dependency I must define?

Thanks in advance for any help.

Here is my build.gradle file.

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.**.*'
        ]
    }
}
G A
  • 15
  • 4

1 Answers1

0

You can access JavaFX Alert.AlertType class, without the need of adding any dependency.

Make sure you are using the latest version of the jfxmobile plugin (1.0.8).

This works on desktop and mobile:

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));
  }
}

If it isn't the case for you, post your build.gradle and any exception you may have.

José Pereda
  • 44,311
  • 7
  • 104
  • 132
  • Thank you, José, for your quick response. Indeed, the code you posted runs with no problem. However, NetBeans gives me a red-line compilation error with the message: "The type of Alert(AltertType,String) is erroneous. The package javafx.scene.control.Alert does not exist." – G A May 26 '16 at 21:05
  • You should be able to run both JavaFX and Gluon's Alert. What is your JDK? JavaFX Alert is available since 8u40, but Gluon already bundles 8u60. – José Pereda May 26 '16 at 21:10
  • JDK according to NetBeans Java Platform is jdk1.8.0_74.jdk. – G A May 26 '16 at 21:20
  • If you check your imports, you'll see you are using other JavaFX classes, without a red mark for them. I've edited my answer with the imports for the view, without any warnings (NetBeans 8.1, Mac OX 10.11.14, JDK 8u92). Try to create a regular JavaFX project in NetBeans, add an Alert and see if still in red. – José Pereda May 26 '16 at 21:52