问题
I'm looking information about javafxports technology and can I use inside this project FXML file.
This is my build.gradle:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'org.javafxports:jfxmobile-plugin:1.1.0'
}
}
apply plugin: 'org.javafxports.jfxmobile'
repositories {
jcenter()
maven {
url 'http://nexus.gluonhq.com/nexus/content/repositories/releases'
}
}
mainClassName = 'com.orden.First'
dependencies {
compile 'com.gluonhq:charm:4.0.0'
// Desktop SQL -> https://github.com/xerial/sqlite-jdbc
desktopRuntime 'org.xerial:sqlite-jdbc:3.8.11.2'
embeddedRuntime 'com.gluonhq:charm-down-plugin-storage-desktop:3.0.0'
// Embedded SQL -> https://github.com/xerial/sqlite-jdbc
embeddedRuntime 'org.xerial:sqlite-jdbc:3.7.2'
// Android SQL -> https://github.com/SQLDroid/SQLDroid
androidRuntime 'org.sqldroid:sqldroid:1.0.3'
// ios SQL -> https://github.com/robovm/robovm 1.8
}
jfxmobile {
downConfig {
version = '3.0.0'
plugins 'display', 'lifecycle', 'statusbar', 'storage'
}
android {
manifest = 'src/android/AndroidManifest.xml'
androidSdk = 'C:/Program Files (x86)/Android/android-sdk/'
}
ios {
infoPList = file('src/ios/Default-Info.plist')
forceLinkClasses = [
'com.gluonhq.**.*',
'javax.annotations.**.*',
'javax.inject.**.*',
'javax.json.**.*',
'org.glassfish.json.**.*',
'SQLite.**.*'
]
}
embedded {
remotePlatforms {
raspberry {
host = '192.168.1.10'
username = 'pi'
password = 'raspberry'
workingDir = '/home/pi/Gluon'
jreLocation = '/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt'
execPrefix = 'sudo'
}
}
}
}
And this is my javaFX first page code:
package com.orden;
import java.io.File;
import java.net.URL;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.geometry.Rectangle2D;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Screen;
import javafx.stage.Stage;
public class First extends Application {
public void start(Stage primaryStage) {
try {
URL url = new File("src/main/java/com/orden/views/MainWindowFXML.fxml").toURL();
URL url2 = new File("src/main/java/com/orden/views/application.css").toURL();
AnchorPane root = (AnchorPane)FXMLLoader.load(url);
Scene scene = new Scene(root);
scene.getStylesheets().add(url2.toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
primaryStage.setTitle("Image saver");
primaryStage.setResizable(true);
} catch(Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
As we can see I use FXML file to define all my graphical structure (controls etc.). Everything compile ok. I also can create .apk file and run my application on smartfon with Android OS. The problem is when I start application I only see black screen , nothing else.
If someone knows how fix this problem I am open on any tips. I need solution step by step because gluon plugin configuration is hard.
Below I presents my file tree:
回答1:
URL url = getClass().getResource("views/MainWindowFXML.fxml");
URL url2 = getClass().getResource("views/application.css");
or
URL url = getClass().getResource("/com/orden/views/MainWindowFXML.fxml");
URL url2 = getClass().getResource("/com/orden/views/application.css");
or
URL url = getClass().getClassLoader().getResource("com/orden/views/MainWindowFXML.fxml");
URL url2 = getClass().getClassLoader().getResource("com/orden/views/application.css");
来源:https://stackoverflow.com/questions/41626292/fxml-file-inside-javafxports-project