JavaFX

ColorPicker/Farbauswahl

Hier ist eine kleine beispielhafte Minianwendung mit einer Farbauswahl:


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.ColorPicker;
import javafx.scene.control.Label;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
 
public class MyFxApplication extends Application {
   Label llInfo;
 
   @Override
   public void start(Stage mainStage) {
      mainStage.setTitle("Mini-JavaFX-Anwendnung");
 
      final BorderPane borderPane = new BorderPane();
 
      final ColorPicker picker = new ColorPicker();
      picker.setOnAction(new EventHandler<ActionEvent>() {
 
         @Override
         public void handle(ActionEvent t) {
            Color value = picker.getValue();
            String colorString = value.toString();
            String substring = colorString.substring(2, colorString.length()-2);
            borderPane.getBottom().setStyle("-fx-background-color: #" + substring);
         }
      });
      borderPane.setCenter(picker);
 
      borderPane.setBottom(new Label("Selected Color"));
 
      Scene scene = new Scene(borderPane, 300, 100);
 
      mainStage.setScene(scene);
      mainStage.show();
   }
 
   public static void main(String[] args) {
      launch(args);
   }
}



Stichworte:

JavaFX ColorPicker, Farbauswahl, Beispielanwendung, Example

Eigene Werkzeuge
Werkzeuge

gratis Counter by GOWEB
seit 9.10.2007