JavaFx:包括边框窗格左侧的图片

时间:2017-05-02 12:11:46

标签: java javafx

我将首先显示代码。

public class prog_aufgabe_2_2 extends Application {



@Override
    public void start(Stage primaryStage) throws FileNotFoundException {

        ///Create BorderPane + add toolbar and Buttons 
        BorderPane borderPane = new BorderPane();
        Button b1 = new Button("open");
        Button b2 = new Button("save");
        Button b3 = new Button("saveAs");
        ToolBar toolBar1 = new ToolBar(); /// Create toolbar align to top
        toolBar1.getItems().addAll(b1,b2,b3); /// Add Buttons to toolbar


        borderPane.setTop(toolBar1);

        ///Image left

        Image image1 = new Image(new FileInputStream("C:\Users\dimi1\Desktop\DMM\Programmiertechniken yi\JavaFx Bilder"));
        ImageView img1 = new ImageView();
        img1.setImage(image1);
        borderPane.setLeft(img1);


        primaryStage.setScene(new Scene(borderPane, 300, 300));
        primaryStage.show();
    }

所以,我尝试添加图片并将其对齐到Borderpane的左侧。当我运行代码时,会出现以下错误:

Exception in Application start method
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
    at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.Error: Unresolved compilation problem: 
    Invalid escape sequence (valid ones are  \b  \t  \n  \f  \r  \"  \'  \\ )

    at Woche_5.prog_aufgabe_2_2.start(prog_aufgabe_2_2.java:33)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863)
    at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    ... 1 more
Exception running application Woche_5.prog_aufgabe_2_2

所以,这就是我认为发生的事情。简单地说......它无法找到图片的路径。此外,在错误消息中,他们希望我更改

的路径
Image image1 = new Image(new FileInputStream("C:\Users\dimi1\Desktop\DMM\Programmiertechniken yi\JavaFx Bilder"));

并将所有\更改为/。

导致问题的原因是什么?如何将图片对齐到左侧?

0 个答案:

没有答案