Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaFX. Add more than one Label with image to Pane
    primarykey
    data
    text
    <p>I want to add two different labels with image in Pane. The code I use is this:</p> <pre><code>import javafx.application.Application; import javafx.scene.Scene; import javafx.stage.Stage; public class Controller extends Application { public static void main(String[] args) { launch(args); } public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("Starting FX"); primaryStage.setScene(new Scene(new Panel(), 590, 390)); primaryStage.setResizable(false); primaryStage.centerOnScreen(); primaryStage.show(); } } import javafx.scene.control.Label; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.Pane; public class Panel extends Pane { private ImageView image = new ImageView(new Image(getClass().getResourceAsStream("red.jpg"))); private Label label1 = new Label(); private Label label2 = new Label(); public Panel() { label1.relocate(524, 280); label1.setGraphic(image); this.getChildren().add(label1); label2.relocate(250, 200); label2.setGraphic(image); this.getChildren().add(label2); } } </code></pre> <p>My problem is that it doesn't add both labels on screen.</p> <p>If I have:</p> <pre><code>this.getChildren().add(label1); this.getChildren().add(label2); </code></pre> <p>it shows only label 2 on screen, even though if I print(this.getchildren()) it has both labels.</p> <p>If I have one of them, it adds it normally.</p> <p>Even if I don't have neither and execute</p> <pre><code>this.getChildren().addAll(label1, label2); </code></pre> <p>still it adds only label2.</p> <p>Why is that?</p> <p>Thank you</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload