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 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);
}
}
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 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);
}
}
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