執行結果:
My.css 檔案
.root {
-fx-background-image: url("Loli.jpg");
-fx-background-size: 675px 600px;
}
.label {
-fx-font-size: 50px;
-fx-font-family: "微軟正黑體";
-fx-font-weight: bold;
-fx-text-fill: #CCAAFF;
-fx-effect: dropshadow( gaussian , rgba(255,255,255,0.5) , 0,0,0,1 );
//dropshadow 參數分別為:模糊類型、RGBA顏色、模糊程度、寬度、水平位移、垂直位移
}
#myStyle1 {
-fx-font-size: 70px;
-fx-font-family: "微軟正黑體";
-fx-fill: #990000;
-fx-font-weight: bold;
-fx-effect: innershadow( three-pass-box , rgba(200,100,255,1) , 5, 0.5 , 0 , 0 );
//innershadow 參數分別為:模糊類型、RGBA顏色、模糊程度、寬度、水平位移、垂直位移,位移部份會被填充
}
NewClass Java 檔案
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class NewClass extends Application {
@Override
public void start(Stage s) {
GridPane grid = new GridPane();
grid.setAlignment(Pos.CENTER);
grid.setHgap(10);
grid.setVgap(10);
grid.setPadding(new Insets(25, 25, 25, 25));
Scene scene = new Scene(grid, 675, 600);
scene.getStylesheets().add(NewClass.class.getResource("My.css").toExternalForm());
Label t1 = new Label("文字測試 A");
grid.add(t1, 0, 0, 2, 1);
Text t2 = new Text("文字測試 B");
t2.setId("myStyle1");
grid.add(t2, 0, 1, 2, 1);
Text t3 = new Text("文字測試 C");
grid.add(t3, 0, 2, 2, 1);
s.setScene(scene);
s.show();
}
public static void main(String[] args) {
launch(args);
}
}
留言列表