Adding Image to Label : Label « JavaFX « Java

Adding Image to Label

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

public class Main extends Application {
  public static void main(String[] args) {

  public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setTitle("Label Sample");

    HBox hbox = new HBox();
    Image image = new Image(getClass().getResourceAsStream("labels.jpg"));
    Label label1 = new Label("Search");
    label1.setGraphic(new ImageView(image));

    ((Group) scene.getRoot()).getChildren().add(hbox);



Related examples in the same category

1.Using Label to display Text
2.Set new value to Label
3.Set Font for Label
4.Set Label Text color
5.Using Rotate to create vertical label
6.Move a Label by using setTranslateY
7.Wrap a Label
8.Scale a Label
9.Label mouse in and out event
10.Change Label text in Button click event