
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
How to create a Polyline using JavaFX?
A Polyline is an open figure formed using n number of lines existing in the same plane. i.e. a polyline is the same as a polygon except it is not closed. In JavaFX a polyline is represented by the javafx.scene.shape.PolyLine class.
To create a polygon you need to −
Instantiate this class.
Pass the start and endpoints, of the line segments to draw a polygon to the class either by passing them as arguments to the constructor or, using the getPoints() method as −
polygon.getPoints().addAll(new Double[]{ List of XY coordinates separated by commas });
Add the created node (shape) to the Group object.
Example
import javafx.application.Application; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.paint.Color; import javafx.stage.Stage; import javafx.scene.shape.Polyline; public class DrawingPolyLine extends Application { public void start(Stage stage) { //Drawing a polygon Polyline poliline = new Polyline(); //Setting the properties of the ellipse poliline.getPoints().addAll(new Double[]{ 150.0, 200.0, 410.0, 200.0, 250.0, 50.0, 250.0, 230.0 }); //Setting other properties poliline.setStrokeWidth(8.0); poliline.setStroke(Color.DARKSLATEGREY); //Setting the Scene Group root = new Group(poliline); Scene scene = new Scene(root, 595, 300, Color.BEIGE); stage.setTitle("Drawing Polyline"); stage.setScene(scene); stage.show(); } public static void main(String args[]){ launch(args); } }
Output
- Related Articles
- How to create a Polygon with Polyline using FabricJS?
- How to create a canvas with Polyline using FabricJS?
- How to create a circle using JavaFX?
- How to create a Rectangle using JavaFX?
- How to create a Line using JavaFX?
- How to create a Polygon using JavaFX?
- How to create a CubicCurve using JavaFX?
- How to create a QuadCurve using JavaFX?
- How to create a label using JavaFX?
- How to create a separator using JavaFX?
- How to create a Menu using JavaFX?
- How to create a ScrollBar using JavaFX?
- How to create a ListView using JavaFX?
- How to create a TreeView using JavaFX?
- How to create a pagination using JavaFX?

Advertisements