VLineTo class is a part of JavaFX. VLineTo class creates a vertical line path from the current position to specified Y coordinate. VLineTo class inherits PathElement class.
Constructor of the class:
- VLineTo(): Creates an empty object of VLineTo.
- VLineTo(double y): Creates an object of VLineTo with specified value of y coordinate.
Commonly Used Methods:
| Method | Explanation |
|---|---|
| getY() | Returns the value of Y coordinate. |
| setY(double v) | Sets the value of Y coordinate. |
| toString() | Returns the string representation of VLineTo object. |
| yProperty() | Defines the Y coordinate. |
Below programs illustrate the use of VLineTo Class:
- Java program to create a path and add VLineTo to it and display it:
- In this program, we will create a Path object named path.
- Create a VLineTo object with specified Y coordinate.
- Then create a MoveTo object named moveto and add the moveto and vlineto 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.
- Call the show() function to display the final results.
// Java program to create a path// and add VLineTo to it and display itimportjavafx.application.Application;importjavafx.scene.Scene;importjavafx.scene.control.*;importjavafx.scene.layout.*;importjavafx.stage.Stage;importjavafx.scene.layout.*;importjavafx.scene.paint.*;importjavafx.scene.text.*;importjavafx.geometry.*;importjavafx.scene.layout.*;importjavafx.scene.shape.*;importjavafx.scene.paint.*;importjavafx.scene.*;ÂÂpublicclassVLineTo_1extendsApplication {   Â// launch the application   Âpublicvoidstart(Stage stage)   Â{       Âtry{           Â// set title for the stage           Âstage.setTitle("VLineTo");           Â// create VLineTo           ÂVLineTo vlineto =newVLineTo(200);           Â// create moveto           ÂMoveTo moveto =newMoveTo(100,100);           Â// create a Path           ÂPath path =newPath(moveto, vlineto);           Â// set fill for path           Âpath.setFill(Color.BLACK);           Â// set stroke width           Âpath.setStrokeWidth(2);           Â// create a Group           ÂGroup group =newGroup(path);           Â// create a scene           ÂScene scene =newScene(group,400,300);           Â// set the scene           Âstage.setScene(scene);           Âstage.show();       Â}       Âcatch(Exception e) {           ÂSystem.out.println(e.getMessage());       Â}   Â}   Â// Main Method   Âpublicstaticvoidmain(String args[])   Â{       Â// launch the application       Âlaunch(args);   Â}}Output:
- Java program to create a path and add multiple VLineTo object to it and display it:
- In this program, we will create a Path object named path.
- Create three VLineTo objects with specified Y coordinate.
- Then Create three MoveTo object named moveto, moveto_1, and moveto_2.
- Add all the moveto and vlineto objects to the path in a order.
- Add this path to Group object and add the group object to the scene and add the scene to the stage.
- Call the show() function to display the final results.
// Java program to create a path and add the// multiple VLineTo object to it and display itimportjavafx.application.Application;importjavafx.scene.Scene;importjavafx.scene.control.*;importjavafx.scene.layout.*;importjavafx.stage.Stage;importjavafx.scene.layout.*;importjavafx.scene.paint.*;importjavafx.scene.text.*;importjavafx.geometry.*;importjavafx.scene.layout.*;importjavafx.scene.shape.*;importjavafx.scene.paint.*;importjavafx.scene.*;ÂÂpublicclassVLineTo_2extendsApplication {   Â// launch the application   Âpublicvoidstart(Stage stage)   Â{       Âtry{           Â// set title for the stage           Âstage.setTitle("VLineTo");           Â// create VLineTo           ÂVLineTo vlineto =newVLineTo(200);           ÂVLineTo vlineto_1 =newVLineTo(250);           ÂVLineTo vlineto_2 =newVLineTo(225);           Â// create moveto           ÂMoveTo moveto =newMoveTo(100,100);           ÂMoveTo moveto_1 =newMoveTo(200,100);           ÂMoveTo moveto_2 =newMoveTo(300,100);           Â// create a Path           ÂPath path =newPath(moveto, vlineto, moveto_1,                          Âvlineto_1, moveto_2, vlineto_2);           Â// set fill for path           Âpath.setFill(Color.BLACK);           Â// set stroke width           Âpath.setStrokeWidth(2);           Â// create a Group           ÂGroup group =newGroup(path);           Â// create a scene           ÂScene scene =newScene(group,400,300);           Â// set the scene           Âstage.setScene(scene);           Âstage.show();       Â}       Âcatch(Exception e) {           ÂSystem.out.println(e.getMessage());       Â}   Â}   Â// Main Method   Âpublicstaticvoidmain(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/VLineTo.html

