JavaFX

ToolBar

Hier ist eine kleine beispielhafte JavaFx-Anwendung mit einer ToolBar:


package com.sowas.javawiki.javafx;
 
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.ToolBar;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
 
public class MyFxApplication extends Application {
   Label llInfo;
 
   @Override
   public void start(Stage mainStage) {
      mainStage.setTitle("Mini-JavaFX-Anwendnung");
 
      BorderPane borderPane = new BorderPane();
      ToolBar toolBar = new ToolBar();
      toolBar.getItems().add(createButton(1));
      toolBar.getItems().add(createButton(2));
      borderPane.setTop(toolBar);
 
      Label llHello = new Label("Hallo World.");
      borderPane.setCenter(llHello);
 
      llInfo = new Label("");
      borderPane.setBottom(llInfo);
 
      Scene scene = new Scene(borderPane, 300, 100);
 
      mainStage.setScene(scene);
      mainStage.show();
   }
 
   private Button createButton(final int n) {
      Button button = new Button("Button " + n);
      button.setOnAction(new EventHandler<ActionEvent>() {
 
         @Override
         public void handle(ActionEvent t) {
            llInfo.setText("Button " + n + " pressed!");
         }
      });
      return button;
   }
 
   public static void main(String[] args) {
      launch(args);
   }
}



Stichworte:

JavaFX ToolBar, Beispielanwendung, Example

Eigene Werkzeuge
Werkzeuge

gratis Counter by GOWEB
seit 9.10.2007