例
import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.paint.Color; import javafx.stage.Stage; public class ButtonExample extends Application { @Override public void start(Stage stage) { //创建一个按钮 Button button = new Button(); //将文本设置为按钮 button.setText("Sample Button"); //设置按钮的位置 button.setTranslateX(150); button.setTranslateY(60); //设置舞台 Group root = new Group(button); Scene scene = new Scene(root, 595, 150, Color.BEIGE); stage.setTitle("Button Example"); stage.setScene(scene); stage.show(); } public static void main(String args[]){ launch(args); } }
输出结果