Saturday 24 October 2020

JavaFX: Shape: strokeType: Defines where to draw the stroke

 

'StrokeType' enum define properties which specify where to draw the stroke around the boundary of a Shape node.

 

Following table summarizes possible values for strokeType.

 

Stroke Type

Description

INSIDE

The stroke is applied by extending the boundary of a closed Shape node into its interior by a distance specified by the strokeWidth.

 

OUTSIDE

 

The stroke is applied by extending the boundary of a closed Shape node outside of its interior by a distance specified by the strokeWidth.

 

CENTERED

 

The stroke is applied by thickening the boundary of the Shape node by a distance of half of the strokeWidth on either side of the boundary.

 

 

Example

<Rectangle fx:id="rectangle" arcHeight="30" arcWidth="30" fill="black"

width="300" height="100" smooth="true" stroke="green" strokeWidth="5"

strokeType="inside"/>

 

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"
		 strokeType="inside"/>
	
	<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