JavaFX | VLineTo Class

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 applicationpublicvoidstart(Stage stage){try{// set title for the stagestage.setTitle("VLineTo");// create VLineToVLineTo vlineto =newVLineTo(200);// create movetoMoveTo moveto =newMoveTo(100,100);// create a PathPath path =newPath(moveto, vlineto);// set fill for pathpath.setFill(Color.BLACK);// set stroke widthpath.setStrokeWidth(2);// create a GroupGroup group =newGroup(path);// create a sceneScene scene =newScene(group,400,300);// set the scenestage.setScene(scene);stage.show();}catch(Exception e) {System.out.println(e.getMessage());}}// Main Methodpublicstaticvoidmain(String args[]){// launch the applicationlaunch(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 applicationpublicvoidstart(Stage stage){try{// set title for the stagestage.setTitle("VLineTo");// create VLineToVLineTo vlineto =newVLineTo(200);VLineTo vlineto_1 =newVLineTo(250);VLineTo vlineto_2 =newVLineTo(225);// create movetoMoveTo moveto =newMoveTo(100,100);MoveTo moveto_1 =newMoveTo(200,100);MoveTo moveto_2 =newMoveTo(300,100);// create a PathPath path =newPath(moveto, vlineto, moveto_1,vlineto_1, moveto_2, vlineto_2);// set fill for pathpath.setFill(Color.BLACK);// set stroke widthpath.setStrokeWidth(2);// create a GroupGroup group =newGroup(path);// create a sceneScene scene =newScene(group,400,300);// set the scenestage.setScene(scene);stage.show();}catch(Exception e) {System.out.println(e.getMessage());}}// Main Methodpublicstaticvoidmain(String args[]){// launch the applicationlaunch(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




