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:

  1. VLineTo(): Creates an empty object of VLineTo.
  2. 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:
    1. In this program, we will create a Path object named path.
    2. Create a VLineTo object with specified Y coordinate.
    3. Then create a MoveTo object named moveto and add the moveto and vlineto object to the path.
    4. Add this path to Group object and add the group object to the scene and add the scene to the stage.
    5. Call the show() function to display the final results.
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // Java program to create a path
    // and add VLineTo 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 VLineTo_1 extends Application {
      
        // launch the application
        public void start(Stage stage)
        {
      
            try {
      
                // set title for the stage
                stage.setTitle("VLineTo");
      
                // create VLineTo
                VLineTo vlineto = new VLineTo(200);
      
                // create moveto
                MoveTo moveto = new MoveTo(100, 100);
      
                // create a Path
                Path path = new Path(moveto, vlineto);
      
                // 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);
        }
    }

    chevron_right

    
    

    Output:

  • Java program to create a path and add multiple VLineTo object to it and display it:
    1. In this program, we will create a Path object named path.
    2. Create three VLineTo objects with specified Y coordinate.
    3. Then Create three MoveTo object named moveto, moveto_1, and moveto_2.
    4. Add all the moveto and vlineto objects to the path in a order.
    5. Add this path to Group object and add the group object to the scene and add the scene to the stage.
    6. Call the show() function to display the final results.
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    // Java program to create a path and add the
    // multiple VLineTo 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 VLineTo_2 extends Application {
      
        // launch the application
        public void start(Stage stage)
        {
      
            try {
      
                // set title for the stage
                stage.setTitle("VLineTo");
      
                // create VLineTo
                VLineTo vlineto = new VLineTo(200);
                VLineTo vlineto_1 = new VLineTo(250);
                VLineTo vlineto_2 = new VLineTo(225);
      
                // create moveto
                MoveTo moveto = new MoveTo(100, 100);
                MoveTo moveto_1 = new MoveTo(200, 100);
                MoveTo moveto_2 = new MoveTo(300, 100);
      
                // create a Path
                Path path = new Path(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 = 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);
        }
    }

    chevron_right

    
    

    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



My Personal Notes arrow_drop_up

Second year Department of Information Technology Jadavpur University

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.