'stroke' property is used to draw a color line around the shape. ‘strokeWidth’ property is used to specify the width of stroke line. Default value for ‘strokeWidth’ is 1.
<Rectangle fx:id="rectangle" arcHeight="30" arcWidth="30" fill="black" width="300" height="100" smooth="true" stroke="green" strokeWidth="5"/>
Find the below working application.
HelloFxmlDemo.fxml
<?import javafx.scene.*?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.text.*?>
<StackPane xmlns:fx="http://javafx.com/fxml" fx:controller="com.sample.app.controller.HelloWorldController">
<Rectangle fx:id="rectangle" arcHeight="30" arcWidth="30" fill="black"
width="300" height="100" smooth="true" stroke="green" strokeWidth="5"/>
<Text fx:id = "text" fill="lightsalmon" text="Hello World" style="-fx-font-weight: bold; -fx-font-size: 30" />
</StackPane>
HelloWorldController.java
package com.sample.app.controller;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
public class HelloWorldController implements Initializable{
@FXML
private Rectangle rectangle;
@FXML
private Text text;
@Override
public void initialize(URL location, ResourceBundle resources) {
// Write custom logic here
}
}
HelloFXML.java
package com.sample.app;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
public class HelloFXML extends Application {
public static void main(String args[]) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = (Parent) FXMLLoader.load(HelloFXML.class.getResource("/HelloFxmlDemo.fxml"));
Scene scene = new Scene(root, 500, 500, Color.WHITE);
primaryStage.setTitle("StackPane Demo");
primaryStage.setScene(scene);
primaryStage.show();
}
}
Output
Previous Next Home
No comments:
Post a Comment