现场演示
->
import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.paint.Color; import javafx.stage.Stage; public class ButtonGraphis extends Application { public void start(Stage stage) { //创建图形(图像) Image img = new Image("UIControls/logo.png"); ImageView view = new ImageView(img); view.setFitHeight(80); view.setPreserveRatio(true); //创建一个按钮 Button button = new Button(); //设置按钮的位置 button.setTranslateX(200); button.setTranslateY(25); //设置按钮的大小 button.setPrefSize(80, 80); //将图形设置为按钮 button.setGraphic(view); //设置舞台 Group root = new Group(button); Scene scene = new Scene(root, 595, 170, Color.BEIGE); stage.setTitle("Button Graphics"); stage.setScene(scene); stage.show(); } public static void main(String args[]){ launch(args); } }
输出结果