- JavaFX Tutorial
- JavaFX - Home
- JavaFX - Overview
- JavaFX Installation and Architecture
- JavaFX - Installation Using Netbeans
- JavaFX - Installation Using Eclipse
- JavaFX - Installation using Visual Studio Code
- JavaFX - Architecture
- JavaFX - Application
- JavaFX 2D Shapes
- JavaFX - 2D Shapes
- JavaFX - Drawing a Line
- JavaFX - Drawing a Rectangle
- JavaFX - Drawing a Rounded Rectangle
- JavaFX - Drawing a Circle
- JavaFX - Drawing an Ellipse
- JavaFX - Drawing a Polygon
- JavaFX - Drawing a Polyline
- JavaFX - Drawing a Cubic Curve
- JavaFX - Drawing a Quad Curve
- JavaFX - Drawing an Arc
- JavaFX - Drawing an SVGPath
- JavaFX Properties of 2D Objects
- JavaFX - Stroke Type Property
- JavaFX - Stroke Width Property
- JavaFX - Stroke Fill Property
- JavaFX - Stroke Property
- JavaFX - Stroke Line Join Property
- JavaFX - Stroke Miter Limit Property
- JavaFX - Stroke Line Cap Property
- JavaFX - Smooth Property
- Operations on 2D Objects
- JavaFX - 2D Shapes Operations
- JavaFX - Union Operation
- JavaFX - Intersection Operation
- JavaFX - Subtraction Operation
- JavaFX Color and Texture
- JavaFX - Colors
- JavaFX Text
- JavaFX - Text
- JavaFX Effects
- JavaFX - Effects
- JavaFX Transformations
- JavaFX - Transformations
- JavaFX Animations
- JavaFX - Animations
- JavaFX Images
- JavaFX - Images
- JavaFX 3D Shapes
- JavaFX - 3D Shapes
- JavaFX - Creating a Box
- JavaFX - Creating a Cylinder
- JavaFX - Creating a Sphere
- Properties of 3D Objects
- JavaFX - Cull Face Property
- JavaFX - Drawing Modes Property
- JavaFX - Material Property
- JavaFX Event Handling
- JavaFX - Event Handling
- JavaFX - Using Convenience Methods
- JavaFX - Event Filters
- JavaFX - Event Handlers
- JavaFX UI Controls
- JavaFX - UI Controls
- JavaFX - ListView
- JavaFX - Accordion
- JavaFX - ButtonBar
- JavaFX - ChoiceBox
- JavaFX - HTMLEditor
- JavaFX - MenuBar
- JavaFX - Pagination
- JavaFX - ProgressIndicator
- JavaFX - ScrollPane
- JavaFX - Separator
- JavaFX - Slider
- JavaFX - Spinner
- JavaFX - SplitPane
- JavaFX - TableView
- JavaFX - TabPane
- JavaFX - ToolBar
- JavaFX - TreeView
- JavaFX - Label
- JavaFX - CheckBox
- JavaFX - RadioButton
- JavaFX - TextField
- JavaFX - PasswordField
- JavaFX - FileChooser
- JavaFX - Hyperlink
- JavaFX - Tooltip
- JavaFX - Alert
- JavaFX - DatePicker
- JavaFX - TextArea
- JavaFX Charts
- JavaFX - Charts
- JavaFX - Creating Pie Chart
- JavaFX - Creating Line Chart
- JavaFX - Creating Area Chart
- JavaFX - Creating Bar Chart
- JavaFX - Creating Bubble Chart
- JavaFX - Creating Scatter Chart
- JavaFX - Creating Stacked Area Chart
- JavaFX - Creating Stacked Bar Chart
- JavaFX Layout Panes
- JavaFX - Layout Panes
- JavaFX - HBox Layout
- JavaFX - VBox Layout
- JavaFX - BorderPane Layout
- JavaFX - StackPane Layout
- JavaFX - TextFlow Layout
- JavaFX - AnchorPane Layout
- JavaFX - TilePane Layout
- JavaFX - GridPane Layout
- JavaFX - FlowPane Layout
- JavaFX CSS
- JavaFX - CSS
- Media with JavaFX
- JavaFX - Playing Video
- JavaFX Useful Resources
- JavaFX - Quick Guide
- JavaFX - Useful Resources
- JavaFX - Discussion
JavaFX - Stroke Line Join Property
JavaFX does not just support drawing a single 2D shape at a time, but also allows you to join multiple 2D shape objects to form another bigger object. For instance, you can use the Rectangle class to draw a rectangle object and also join four line objects together to form a rectangle.
In such cases where multiple lines are used to form a 2D shape, JavaFX supports various properties to be applied on these line while combining them together. One such property is Stroke Line Join Property.
Stroke Line Join Property
The Stroke Line Join Property is used to designate the shape of the joint used to combine two line objects while forming another shape.
This property is of the type StrokeLineJoin, it represents the type of joining that is used at the edges of the shape.
The stroke line join is of three types. It is represented by the three constants of StrokeLineJoin as follows −
Bevel − In bevel join, the outside edges of the intersection are connected with a line segment.
Miter − In miter join, the outside edges of the intersection are joined together forming a sharp edge.
Round − In round join, the outside edges of the intersection are joined by rounding off the corner, the radius of this will be exactly half the width of the join.
You can set the line join of the stroke using the method setStrokeLineJoin() as follows −
path.setStrokeLineJoin(StrokeLineJoin.[Type_of_Join]);
The Type_of_Join can be set using any of the following keywords:
StrokeLineJoin.BEVEL − To set the stroke line join to bevel join.
StrokeLineJoin.MITER − To set the stroke line join to miter join.
StrokeLineJoin.ROUND − To set the stroke line join to round join.
By default, the Stroke Line Joining a shape is miter. Following is a diagram of a triangle with different line join types −
Example
Let us see an example demonstrating the usage of Stroke Line Join property on a triangle. Save this file with the name StrokeLineJoinExample.java.
import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.shape.Polygon; import javafx.scene.shape.StrokeLineJoin; import javafx.scene.paint.Color; import javafx.stage.Stage; public class StrokeLineJoinExample extends Application { @Override public void start(Stage stage) { //Creating a Triangle Polygon triangle = new Polygon(); //Adding coordinates to the polygon triangle.getPoints().addAll(new Double[]{ 100.0, 50.0, 170.0, 150.0, 100.0, 250.0, }); triangle.setFill(Color.BLUE); triangle.setStroke(Color.BLACK); triangle.setStrokeWidth(7.0); triangle.setStrokeLineJoin(StrokeLineJoin.BEVEL); //Creating a Group object Group root = new Group(triangle); //Creating a scene object Scene scene = new Scene(root, 300, 300); //Setting title to the Stage stage.setTitle("Drawing a Triangle"); //Adding scene to the stage stage.setScene(scene); //Displaying the contents of the stage stage.show(); } public static void main(String args[]){ launch(args); } }
Compile and execute the saved java file from the command prompt using the following commands.
javac --module-path %PATH_TO_FX% --add-modules javafx.controls StrokeLineJoinExample.java java --module-path %PATH_TO_FX% --add-modules javafx.controls StrokeLineJoinExample
Output
On executing, the above program generates a JavaFX window displaying a triangle with bevel stroke line join as shown below.
Example
Let us see an example demonstrating the usage of ROUND Stroke Line Join property on a Rectangle. Save this file with the name StrokeLineJoinRectangle.java.
import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.shape.Polygon; import javafx.scene.shape.StrokeLineJoin; import javafx.scene.paint.Color; import javafx.stage.Stage; public class StrokeLineJoinRectangle extends Application { @Override public void start(Stage stage) { //Creating a Rectangle Polygon rectangle = new Polygon(); //Adding coordinates to the polygon rectangle.getPoints().addAll(new Double[]{ 100.0, 50.0, 170.0, 50.0, 170.0, 250.0, 100.0, 250.0, }); rectangle.setFill(Color.ORANGE); rectangle.setStroke(Color.BLACK); rectangle.setStrokeWidth(5.0); rectangle.setStrokeLineJoin(StrokeLineJoin.ROUND); //Creating a Group object Group root = new Group(rectangle); //Creating a scene object Scene scene = new Scene(root, 300, 300); //Setting title to the Stage stage.setTitle("Drawing a Rectangle"); //Adding scene to the stage stage.setScene(scene); //Displaying the contents of the stage stage.show(); } public static void main(String args[]){ launch(args); } }
Compile and execute the saved java file from the command prompt using the following commands.
javac --module-path %PATH_TO_FX% --add-modules javafx.controls StrokeLineJoinRectangle.java java --module-path %PATH_TO_FX% --add-modules javafx.controls StrokeLineJoinRectangle
Output
On executing, the above program generates a JavaFX window displaying a triangle with bevel stroke line join as shown below.