get JavaFX Button Graphic - Java JavaFX

Java examples for JavaFX:Button

Description

get JavaFX Button Graphic

Demo Code


import java.io.InputStream;
import java.util.logging.Logger;
import javafx.geometry.Pos;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.control.MenuItem;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.text.Font;

public class Main{
    private static Logger LOGGER = Logger
            .getLogger(FxUtils.class.getName());
    public static ImageView getButtonGraphic(String graphic) {

        InputStream is = FxUtils.class.getResourceAsStream(graphic);
        if (is == null) {
            LOGGER.warning("Graphic not found: " + graphic);

        } else {/*from ww w .jav a2s  .  co m*/
            Image img = new Image(is);
            ImageView imgView = new ImageView(img);
            imgView.setFitHeight(16);
            imgView.setFitWidth(16);
            return imgView;

        }

        return null;

    }
}

Related Tutorials