Armand
Armand

Reputation: 11

Javafx scrollpane

I have made a button and I need to create a new scene and add a scrollpane to scroll some text when I type the button. But I want to set an image as a background, but for some reason the background is white. Idk how to fix it.

    bt_about.setOnAction(event -> {
        Text about = new Text();
        ScrollPane textPane = new ScrollPane();
        Image image2 = new Image("C:/Users/User/Pictures/nightsky.jpg");
        about.setFont(Font.font("Georgia", 50));
        about.setFill(Color.BLACK);
        about.setLayoutY(220);
        about.setLayoutX(290);

        textPane.setContent(about);
        textPane.setPrefSize(1100, 780);

        AnchorPane a_pane = new AnchorPane();
        a_pane.getChildren().add(textPane);

        BackgroundImage bImg = new BackgroundImage(image2,
                BackgroundRepeat.NO_REPEAT,
                BackgroundRepeat.NO_REPEAT,
                BackgroundPosition.DEFAULT,
                BackgroundSize.DEFAULT
        );
        Background bGround = new Background(bImg);
        a_pane.setBackground(bGround);

        Scene scene1 = new Scene(a_pane, 1100, 780);
        stage.setScene(scene1);
        stage.show();
    });

I tried adding the scrollpane to stackpane and setting the scrollpane background transparent and the stackpane background the image I want. But that didn't work. I tried using css but that didn't work either.(Somebody help)

Upvotes: 0

Views: 69

Answers (1)

Giovanni Contreras
Giovanni Contreras

Reputation: 2579

Your textPane object is overlaping your background image because textPane has the same size as the scene

textPane

textPane.setPrefSize(1100, 780);

scene

Scene scene1=new Scene(a_pane,1100,780);

It's a design problem . You can delete textPane.setPrefSize(1100, 780); statement and see the background image underneath

Upvotes: 1

Related Questions