本文整理汇总了Java中javafx.fxml.FXMLLoader.setClassLoader方法的典型用法代码示例。如果您正苦于以下问题:Java FXMLLoader.setClassLoader方法的具体用法?Java FXMLLoader.setClassLoader怎么用?Java FXMLLoader.setClassLoader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.fxml.FXMLLoader
的用法示例。
在下文中一共展示了FXMLLoader.setClassLoader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import javafx.fxml.FXMLLoader; //导入方法依赖的package包/类
/**
* This is the method JavaFX calls to start the program.
* @param stage the equivalent to a JFrame in Swing, but created by JavaFX
*/
@Override
public void start(Stage stage) throws Exception {
//Tell javafx to use the main_window.fxml file
FXMLLoader loader = new FXMLLoader(getClass().getResource("main_window.fxml"));
loader.setClassLoader(getClass().getClassLoader());
Parent root = loader.load();
controller = loader.getController();
stage.setScene(new Scene(root, 1100, 985));
stage.setTitle("Scribble");
stage.setResizable(false);
stage.show();
hasStarted = true;
//Test code
String[] names = {"Billy", "Veronica", "José", "Trista"};
setPlayerNames(names);
setPlayer1Score(1);
setPlayer2Score(10000);
setPlayer3Score(9001);
setPlayer4Score(1337);
}
示例2: ClickableBitcoinAddress
import javafx.fxml.FXMLLoader; //导入方法依赖的package包/类
public ClickableBitcoinAddress() {
try {
FXMLLoader loader = new FXMLLoader(getClass().getResource("bitcoin_address.fxml"));
loader.setRoot(this);
loader.setController(this);
// The following line is supposed to help Scene Builder, although it doesn't seem to be needed for me.
loader.setClassLoader(getClass().getClassLoader());
loader.load();
AwesomeDude.setIcon(copyWidget, AwesomeIcon.COPY);
Tooltip.install(copyWidget, new Tooltip("Copy address to clipboard"));
AwesomeDude.setIcon(qrCode, AwesomeIcon.QRCODE);
Tooltip.install(qrCode, new Tooltip("Show a barcode scannable with a mobile phone for this address"));
addressStr = convert(address);
addressLabel.textProperty().bind(addressStr);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例3: viewFor
import javafx.fxml.FXMLLoader; //导入方法依赖的package包/类
/**
* Create an instance for a ParametrizedController annotated class.
*/
public static <T> Optional<T> viewFor(Class<T> annotatedClass) {
ParametrizedController controller = annotatedClass.getAnnotation(ParametrizedController.class);
if (controller != null) { //NOPMD readability
try {
FXMLLoader loader = new FXMLLoader(annotatedClass.getResource(controller.value()));
loader.setClassLoader(annotatedClass.getClassLoader());
loader.load();
return Optional.of(loader.getController());
} catch (IOException e) {
throw new RuntimeException("Could not instantiate the FXML controller", e);
}
}
return Optional.empty();
}