JavaFX | LineTo class Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report LineTo class is a part of JavaFX. LineTo class draws a line from the current position to specified x and y coordinate. LineTo class inherits PathElement class. Constructor of the class: LineTo(): Creates a new LineTo object. LineTo(double x, double y): Creates a new LineTo object with specified x, y coordinates. Commonly Used Methods: Method Explanation getX() Returns the value of X coordinate. getY() Returns the value of Y coordinate. setX(double v) Sets the value of X coordinate. setY(double v) Sets the value of Y coordinate. xProperty() Defines the X coordinate. yProperty() Defines the Y coordinate. Below programs illustrate the use of LineTo Class: Java program to create a path and add LineTo object to it and display it: In this program, we will create a Path object named path. Create an HLineTo object with specified X and Y coordinate. Then create a MoveTo object named moveto. Now add the MoveTo and Lineto object to the path. Add this path to Group object and add the group object to the scene and add the scene to the stage and call the show() function to display the final results. Java // Java program to create a path and // add LineTo object to it and display it import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.Stage; import javafx.scene.layout.*; import javafx.scene.paint.*; import javafx.scene.text.*; import javafx.geometry.*; import javafx.scene.layout.*; import javafx.scene.shape.*; import javafx.scene.paint.*; import javafx.scene.*; public class LineTo_1 extends Application { // launch the application public void start(Stage stage) { try { // set title for the stage stage.setTitle("LineTo"); // create LineTo LineTo Lineto = new LineTo(200, 200); // create moveto MoveTo moveto = new MoveTo(100, 100); // create a Path Path path = new Path(moveto, Lineto); // set fill for path path.setFill(Color.BLACK); // set stroke width path.setStrokeWidth(2); // create a Group Group group = new Group(path); // create a scene Scene scene = new Scene(group, 400, 300); // set the scene stage.setScene(scene); stage.show(); } catch (Exception e) { System.out.println(e.getMessage()); } } // Main Method public static void main(String args[]) { // launch the application launch(args); } } Output: Java program to create a path and add multiple LineTo objects to it and display it: In this program, we will create a Path object named path. Create four LineTo object with specified X and Y coordinates names Lineto, Lineto1, Lineto2, Lineto3. Then create a MoveTo object named moveto. Now add the MoveTo and Lineto objects to the path. Add this path to Group object and add the group object to the scene and add the scene to the stage and call the show() function to display the final results. Java // Java program to create a path and // add multiple LineTo objects to it // and display it import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.*; import javafx.stage.Stage; import javafx.scene.layout.*; import javafx.scene.paint.*; import javafx.scene.text.*; import javafx.geometry.*; import javafx.scene.layout.*; import javafx.scene.shape.*; import javafx.scene.paint.*; import javafx.scene.*; public class LineTo_2 extends Application { // launch the application public void start(Stage stage) { try { // set title for the stage stage.setTitle("LineTo"); // create LineTo LineTo Lineto = new LineTo(300, 200); LineTo Lineto1 = new LineTo(200, 300); LineTo Lineto2 = new LineTo(100, 200); LineTo Lineto3 = new LineTo(200, 100); // create moveto MoveTo moveto = new MoveTo(200, 100); // create a Path Path path = new Path(moveto, Lineto, Lineto1, Lineto2, Lineto3); // set fill for path path.setFill(Color.GREEN); // set stroke width path.setStrokeWidth(2); // create a Group Group group = new Group(path); // create a scene Scene scene = new Scene(group, 400, 400); // set the scene stage.setScene(scene); stage.show(); } catch (Exception e) { System.out.println(e.getMessage()); } } // Main Method public static void main(String args[]) { // launch the application launch(args); } } Output: Note: The above programs might not run in an online IDE please use an offline compiler. Reference: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/shape/LineTo.html Create Quiz Comment A andrew1234 Follow 0 Improve A andrew1234 Follow 0 Improve Article Tags : Java JavaFX Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like