1  import javafx.application.Application;
  2  import javafx.stage.Stage;
  3  import javafx.scene.Scene;
  4  import javafx.scene.control.ContentDisplay;
  5  import javafx.scene.control.Label;
  6  import javafx.scene.image.Image;
  7  import javafx.scene.image.ImageView;
  8  import javafx.scene.layout.HBox;
  9  import javafx.scene.layout.StackPane;
 10  import javafx.scene.paint.Color;
 11  import javafx.scene.shape.Circle;
 12  import javafx.scene.shape.Rectangle;
 13  import javafx.scene.shape.Ellipse;
 14  
 15  public class LabelWithGraphic extends Application {
 16    @Override // Override the start method in the Application class
 17    public void start(Stage primaryStage) {
 18      ImageView us = new ImageView(new Image("image/us.gif"));
 19      Label lb1 = new Label("US\n50 States", us);
 20      lb1.setStyle("-fx-border-color: green; -fx-border-width: 2");
 21      lb1.setContentDisplay(ContentDisplay.BOTTOM);
 22      lb1.setTextFill(Color.RED);
 23      
 24      Label lb2 = new Label("Circle", new Circle(50, 50, 25));
 25      lb2.setContentDisplay(ContentDisplay.TOP);
 26      lb2.setTextFill(Color.ORANGE);
 27  
 28      Label lb3 = new Label("Rectangle", new Rectangle(10, 10, 50, 25));
 29      lb3.setContentDisplay(ContentDisplay.RIGHT);
 30      
 31      Label lb4 = new Label("Ellipse", new Ellipse(50, 50, 50, 25));
 32      lb4.setContentDisplay(ContentDisplay.LEFT);
 33  
 34      Ellipse ellipse = new Ellipse(50, 50, 50, 25);
 35      ellipse.setStroke(Color.GREEN);
 36      ellipse.setFill(Color.WHITE);
 37      StackPane stackPane = new StackPane();
 38      stackPane.getChildren().addAll(ellipse, new Label("JavaFX"));
 39      Label lb5 = new Label("A pane inside a label", stackPane);
 40      lb5.setContentDisplay(ContentDisplay.BOTTOM);
 41      
 42      HBox pane = new HBox(20);
 43      pane.getChildren().addAll(lb1, lb2, lb3, lb4, lb5);
 44  
 45      // Create a scene and place it in the stage
 46      Scene scene = new Scene(pane, 450, 150);
 47      primaryStage.setTitle("LabelWithGraphic"); // Set the stage title
 48      primaryStage.setScene(scene); // Place the scene in the stage
 49      primaryStage.show(); // Display the stage
 50    }
 51  
 52    /**
 53     * The main method is only needed for the IDE with limited
 54     * JavaFX support. Not needed for running from the command line.
 55     */
 56    public static void main(String[] args) {
 57      launch(args);
 58    }
 59  }