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
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
46 Scene scene = new Scene(pane, 450, 150);
47 primaryStage.setTitle("LabelWithGraphic");
48 primaryStage.setScene(scene);
49 primaryStage.show();
50 }
51
52
56 public static void main(String[] args) {
57 launch(args);
58 }
59 }