FXML tutorial (18) – użycie %20
Sekwencji %20
używamy do zastępowania spacji w adresach URL.
listing18_percent.fxml
span class="s0"><?xml version="1.0" encoding="UTF-8"?> <?import javafx.scene.layout.VBox?> <?import javafx.scene.image.Image?> <?import javafx.scene.image.ImageView?> <VBox xmlns:fx="http://javafx.com/fxml"> <fx:define> <Image url="@ten%20kwiatek.jpg" fx:id="kwiatek" /> </fx:define> <ImageView image="$kwiatek" /> </VBox>
Analizator składni podkreśli %20
jako nieprawidłowość, ale kod jest prawidłowy i uruchamia się bez problemów.
Listing18_percent.java
package codes; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.scene.layout.VBox; import javafx.stage.Stage; import java.net.URL; public class Listing18_percent extends Application { public static void main(String[] args) { Application.launch(args); } @Override public void start(Stage stage) { try { URL fxmlUrl = this.getClass().getClassLoader() .getResource("resources/listing18_percent.fxml"); VBox root = fxmlUrl != null ? FXMLLoader.load(fxmlUrl) : new VBox(); Scene scene = new Scene(root, 300, 250); stage.setScene(scene); stage.show(); } catch (Exception e) { e.printStackTrace(); } } }
Po uruchomieniu zobaczymy: