--------------------------------------------
1) text.css
--------------------------------------------
#root {-fx-background-color: linear-gradient(green, darkgray); }
#text {-fx-fill:linear-gradient(pink, orangered); }
------------------------------------------------
2) StylingTextEx.java
------------------------------------------------
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class StylingTextEx extends Application {
public void start(Stage stage) {
initUI(stage);
}
private void initUI(Stage stage) {
HBox root = new HBox();
root.setPadding(new Insets(20));
Text text = new Text("Sateesh Bagadhi");
text.setFont(Font.font("Serif", FontWeight.BOLD, 76));
text.setId("text");
root.setId("root");
root.getChildren().addAll(text);
Scene scene = new Scene(root);
scene.getStylesheets().add(this.getClass().getResource("text.css")
.toExternalForm());
stage.setTitle("Styling text");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
1) text.css
--------------------------------------------
#root {-fx-background-color: linear-gradient(green, darkgray); }
#text {-fx-fill:linear-gradient(pink, orangered); }
------------------------------------------------
2) StylingTextEx.java
------------------------------------------------
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
public class StylingTextEx extends Application {
public void start(Stage stage) {
initUI(stage);
}
private void initUI(Stage stage) {
HBox root = new HBox();
root.setPadding(new Insets(20));
Text text = new Text("Sateesh Bagadhi");
text.setFont(Font.font("Serif", FontWeight.BOLD, 76));
text.setId("text");
root.setId("root");
root.getChildren().addAll(text);
Scene scene = new Scene(root);
scene.getStylesheets().add(this.getClass().getResource("text.css")
.toExternalForm());
stage.setTitle("Styling text");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
No comments:
Post a Comment