Friday, August 16, 2013

Simple example of using JavaFX ToolBar

Simple example of JavaFX ToolBar


package javafx_toolbar;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ToolBar;
import javafx.stage.Stage;
/**
 *
 * @web http://java-buddy.blogspot.com/
 */
public class JavaFX_ToolBar extends Application {
 
 @Override
 public void start(Stage primaryStage) {
 
 Button toolButton1 = new Button("Tool 1");
 toolButton1.setOnAction(new EventHandler<ActionEvent>() {
 @Override
 public void handle(ActionEvent t) {
 System.out.println("Tool 1 clicked!");
 }
 });
 
 ToolBar toolBar = new ToolBar();
 toolBar.getItems().add(toolButton1);
 toolBar.getItems().add(new Button("Tool Opt2"));
 toolBar.getItems().add(new Button("Tool Opt3"));
 toolBar.setPrefWidth(300);
 
 Group root = new Group();
 root.getChildren().add(toolBar);
 
 Scene scene = new Scene(root, 300, 250);
 
 primaryStage.setTitle("java-buddy.blogspot.com");
 primaryStage.setScene(scene);
 primaryStage.show();
 }
 public static void main(String[] args) {
 launch(args);
 }
}


No comments:

Post a Comment

[フレーム]

Subscribe to: Post Comments (Atom)

AltStyle によって変換されたページ (->オリジナル) /