Set CSS style : CSS « JavaFX « Java






Set CSS style

 
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;

public class Main extends Application {

  @Override
  public void start(Stage stage) {
    Group root = new Group();
    Scene scene = new Scene(root, 260, 80);
    stage.setScene(scene);
    stage.setTitle("");

    VBox vb = new VBox();

    Pane canvas = new Pane();
    canvas.setStyle("-fx-background-color: black;");
    canvas.setPrefSize(200,200);
    Circle circle = new Circle(50,Color.BLUE);
    circle.relocate(20, 20);
    Rectangle rectangle = new Rectangle(100,100,Color.RED);
    rectangle.relocate(70,70);
    canvas.getChildren().addAll(circle,rectangle);
    
    vb.getChildren().add(canvas);
    
    scene.setRoot(vb);
    stage.show();
  }

  public static void main(String[] args) {
    launch(args);
  }
}

   
  








Related examples in the same category

1.Using CSS to style the border
2.Connect to CSS Style Sheet in same Package
3.Connect to CSS Style Sheet in another Package
4.-fx-stroke: green;
5.-fx-stroke-width: 5;
6.-fx-stroke-dash-array: 12 2 4 2;
7.-fx-stroke-dash-offset: 6;
8.-fx-stroke-line-cap: butt;
9.-fx-background-color: transparent;
10.-fx-border-color: white;
11.-fx-background-radius: 30;
12.-fx-border-radius: 30;
13.-fx-text-fill: white;
14.-fx-font-weight: bold;
15.-fx-font-size: 14px;
16.-fx-padding: 10 20 10 20;
17.Chart -fx-background-color: rgba(0,168,355,0.05);
18.Chart -fx-border-color: rgba(0,16,35,0.5) rgba(0,68,55,0.6) transparent rgba(0,68,55,0.7);
19.Set css file to Scene
20.Use addAll() to attach several stylesheets.
21.Set Control Id and use it in css
22.Sample application that shows the use of CSS with the different layout panes provided by the JavaFX layout API.
23.-fx-fill: red;