本文整理汇总了Java中javafx.scene.shape.Rectangle.setTranslateX方法的典型用法代码示例。如果您正苦于以下问题:Java Rectangle.setTranslateX方法的具体用法?Java Rectangle.setTranslateX怎么用?Java Rectangle.setTranslateX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javafx.scene.shape.Rectangle
的用法示例。
在下文中一共展示了Rectangle.setTranslateX方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setFillImageKeepingAspectRatio
import javafx.scene.shape.Rectangle; //导入方法依赖的package包/类
public void setFillImageKeepingAspectRatio(Rectangle rectangle, Image image, Dimension2D gamingContextDimension2D) {
double imageWidth = image.getWidth();
double imageHeight = image.getHeight();
double imageHeightToWidthRatio = imageHeight / imageWidth;
double initialHeight = rectangle.getHeight();
double initialWidth = initialHeight / imageHeightToWidthRatio;
double positionX = (gamingContextDimension2D.getWidth() - initialWidth) / 2;
double positionY = (gamingContextDimension2D.getHeight() - initialHeight) / 2;
rectangle.setFill(new ImagePattern(image));
rectangle.setX(positionX);
rectangle.setY(positionY);
rectangle.setWidth(initialWidth);
rectangle.setHeight(initialHeight);
rectangle.setTranslateX(0);
rectangle.setScaleX(1);
rectangle.setScaleY(1);
rectangle.setScaleZ(1);
}
示例2: createRectangle
import javafx.scene.shape.Rectangle; //导入方法依赖的package包/类
public static Group createRectangle(Color color, double tx, double ty, double sx, double sy) {
Group squareGroup = new Group();
Rectangle squareShape = new Rectangle(1.0, 1.0);
squareShape.setFill(color);
squareShape.setTranslateX(-0.5);
squareShape.setTranslateY(-0.5);
squareGroup.getChildren().add(squareShape);
squareGroup.setTranslateX(tx);
squareGroup.setTranslateY(ty);
squareGroup.setScaleX(sx);
squareGroup.setScaleY(sy);
return squareGroup;
}
示例3: PauseTransitionSample
import javafx.scene.shape.Rectangle; //导入方法依赖的package包/类
public PauseTransitionSample() {
super(400,150);
// create rectangle
Rectangle rect = new Rectangle(-25,-25,50, 50);
rect.setArcHeight(15);
rect.setArcWidth(15);
rect.setFill(Color.CRIMSON);
rect.setTranslateX(50);
rect.setTranslateY(75);
getChildren().add(rect);
animation = SequentialTransitionBuilder.create()
.node(rect)
.children(
TranslateTransitionBuilder.create()
.duration(Duration.seconds(2))
.fromX(50)
.toX(200)
.build(),
PauseTransitionBuilder.create()
.duration(Duration.seconds(2))
.build(),
TranslateTransitionBuilder.create()
.duration(Duration.seconds(2))
.fromX(200)
.toX(350)
.build()
)
.cycleCount(Timeline.INDEFINITE)
.autoReverse(true)
.build();
}
示例4: TranslateSample
import javafx.scene.shape.Rectangle; //导入方法依赖的package包/类
public TranslateSample() {
super(230, 220);
//create 2 rectangles with different color
Rectangle rect1 = new Rectangle(90, 90, Color.web("#ed4b00", 0.75));
Rectangle rect2 = new Rectangle(90, 90, Color.web("#ed4b00", 0.5));
//translate second one
rect2.setTranslateX(140);
// rectangle with adjustable translate
Rectangle rect3 = new Rectangle(40, 130, 60, 60);
rect3.setFill(Color.DODGERBLUE);
rect3.setTranslateX(20);
rect3.setTranslateY(10);
//show the rectangles
getChildren().addAll(rect2, rect1, rect3);
// REMOVE ME
setControls(
new SimplePropertySheet.PropDesc("Translate X", rect3.translateXProperty(), 0d, 50d),
new SimplePropertySheet.PropDesc("Translate Y", rect3.translateYProperty(), 0d, 50d)
);
// END REMOVE ME
//create arrow
Polygon polygon = createArrow();
polygon.setLayoutX(110);
polygon.setLayoutY(30);
polygon.setRotate(90);
getChildren().addAll(polygon);
}
示例5: NodePropertiesSample
import javafx.scene.shape.Rectangle; //导入方法依赖的package包/类
public NodePropertiesSample() {
super(300,100);
//X position of node = X + LayoutX + TranslateX
rectA = new Rectangle(50, 50, Color.LIGHTSALMON);
//set position of node temporary (can be changed after)
rectA.setTranslateX(10);
rectB = new Rectangle(50, 50, Color.LIGHTGREEN);
//set position of node when addinf to some layout
rectB.setLayoutX(20);
rectB.setLayoutY(10);
rectC = new Rectangle(50, 50, Color.DODGERBLUE);
//last posibility of setting X position of node
rectC.setX(30);
rectC.setY(20);
//opacity of node can be set
rectC.setOpacity(0.8);
// REMOVE ME
setControls(
new SimplePropertySheet.PropDesc("Rectangle A translate X", rectA.translateXProperty(), 0d, 50d),
new SimplePropertySheet.PropDesc("Rectangle B translate X", rectB.translateXProperty(), 0d, 50d),
new SimplePropertySheet.PropDesc("Rectangle C translate X", rectC.translateXProperty(), 0d, 50d),
new SimplePropertySheet.PropDesc("Rectangle A Opacity", rectA.opacityProperty(), 0d, 1d),
new SimplePropertySheet.PropDesc("Rectangle B Opacity", rectB.opacityProperty(), 0d, 1d),
new SimplePropertySheet.PropDesc("Rectangle C Opacity", rectC.opacityProperty(), 0d, 1d)
);
getChildren().add(createRadioButtons());
// END REMOVE ME
Group g = new Group(rectA, rectB, rectC);
g.setLayoutX(160 + 35);
getChildren().addAll(g);
}
示例6: doorClosed
import javafx.scene.shape.Rectangle; //导入方法依赖的package包/类
public void doorClosed() {
// Draw trim
Rectangle rgDT = new Rectangle(WIDTH, HEIGHT);
rgDT.setFill(Color.web("4d2626"));
this.getChildren().add(rgDT);
// Draw door
Rectangle rgDD = new Rectangle(WIDTH - (WIDTH / (WIDTH / 4)), HEIGHT - (HEIGHT / (HEIGHT / 2)));
rgDD.setTranslateX((WIDTH / (WIDTH / 2)));
rgDD.setTranslateY((HEIGHT / (HEIGHT / 2)));
rgDD.setFill(Color.web("673232"));
this.getChildren().add(rgDD);
// Draw three hinges
VBox vbHinges = new VBox(WIDTH / 3);
Rectangle rgDH1 = new Rectangle((WIDTH / (WIDTH / 2)), (HEIGHT / (HEIGHT / 8)));
rgDH1.setFill(Color.web("a5a5a5"));
Rectangle rgDH2 = new Rectangle((WIDTH / (WIDTH / 2)), (HEIGHT / (HEIGHT / 8)));
rgDH2.setFill(Color.web("a5a5a5"));
Rectangle rgDH3 = new Rectangle((WIDTH / (WIDTH / 2)), (HEIGHT / (HEIGHT / 8)));
rgDH3.setFill(Color.web("a5a5a5"));
vbHinges.getChildren().addAll(rgDH1, rgDH2, rgDH3);
vbHinges.setTranslateX(rgDH1.getWidth() / 2);
vbHinges.setTranslateY(rgDH1.getHeight());
this.getChildren().add(vbHinges);
// Draw door handle block
Rectangle rgDHM = new Rectangle((WIDTH / (WIDTH / 4)), (WIDTH / (WIDTH / 4)));
rgDHM.setTranslateX(WIDTH - rgDHM.getWidth() * 2);
rgDHM.setTranslateY(HEIGHT / 2 - rgDHM.getHeight() / 2);
rgDHM.setFill(Color.web("bfbfbf"));
this.getChildren().add(rgDHM);
// Draw door handle
Rectangle rgDHL = new Rectangle((WIDTH / (WIDTH / 8)), (WIDTH / (WIDTH / 2)));
rgDHL.setTranslateX(WIDTH - rgDHL.getWidth() * 2);
rgDHL.setTranslateY(HEIGHT / 2 - rgDHL.getHeight() / 2);
rgDHL.setFill(Color.web("a5a5a5"));
this.getChildren().add(rgDHL);
}
示例7: doorOpen
import javafx.scene.shape.Rectangle; //导入方法依赖的package包/类
public void doorOpen() {
// Draw trim
Rectangle rgDT = new Rectangle(WIDTH, HEIGHT);
rgDT.setFill(Color.TRANSPARENT);
rgDT.setStroke(Color.web("4d2626"));
rgDT.setStrokeWidth((WIDTH / (WIDTH / 2)));
this.getChildren().add(rgDT);
// Draw three hinges
VBox vbHinges = new VBox(WIDTH / 3);
Rectangle rgDH1 = new Rectangle((WIDTH / (WIDTH / 2)), (HEIGHT / (HEIGHT / 8)));
rgDH1.setFill(Color.web("a5a5a5"));
Rectangle rgDH2 = new Rectangle((WIDTH / (WIDTH / 2)), (HEIGHT / (HEIGHT / 8)));
rgDH2.setFill(Color.web("a5a5a5"));
Rectangle rgDH3 = new Rectangle((WIDTH / (WIDTH / 2)), (HEIGHT / (HEIGHT / 8)));
rgDH3.setFill(Color.web("a5a5a5"));
vbHinges.getChildren().addAll(rgDH1, rgDH2, rgDH3);
vbHinges.setTranslateX(rgDH1.getWidth() / 2);
vbHinges.setTranslateY(rgDH1.getHeight());
this.getChildren().add(vbHinges);
// Draw door
Rectangle rgDD = new Rectangle(WIDTH - (WIDTH / (WIDTH / 4)), HEIGHT);
rgDD.setTranslateX((WIDTH / (WIDTH / 2)) - rgDD.getWidth());
rgDD.setTranslateY((HEIGHT / (HEIGHT / 2)) / 2);
rgDD.setFill(Color.web("673232"));
this.getChildren().add(rgDD);
}
示例8: doorClosed
import javafx.scene.shape.Rectangle; //导入方法依赖的package包/类
public void doorClosed() {
// Draw trim
Rectangle rgDT = new Rectangle(WIDTH, HEIGHT);
rgDT.setFill(Color.web("4d2626"));
this.getChildren().add(rgDT);
// Draw door
Rectangle rgDD = new Rectangle(WIDTH - (WIDTH / (WIDTH / 4)) , HEIGHT - (HEIGHT / (HEIGHT / 2)));
rgDD.setTranslateX((WIDTH / (WIDTH / 2)));
rgDD.setTranslateY((HEIGHT / (HEIGHT / 2)));
rgDD.setFill(Color.web("673232"));
this.getChildren().add(rgDD);
// Draw three hinges
VBox vbHinges = new VBox(WIDTH / 3);
Rectangle rgDH1 = new Rectangle((WIDTH / (WIDTH / 2)), (HEIGHT / (HEIGHT / 8)));
rgDH1.setFill(Color.web("a5a5a5"));
Rectangle rgDH2 = new Rectangle((WIDTH / (WIDTH / 2)), (HEIGHT / (HEIGHT / 8)));
rgDH2.setFill(Color.web("a5a5a5"));
Rectangle rgDH3 = new Rectangle((WIDTH / (WIDTH / 2)), (HEIGHT / (HEIGHT / 8)));
rgDH3.setFill(Color.web("a5a5a5"));
vbHinges.getChildren().addAll(rgDH1, rgDH2, rgDH3);
vbHinges.setTranslateX(rgDH1.getWidth() / 2);
vbHinges.setTranslateY(rgDH1.getHeight());
this.getChildren().add(vbHinges);
// Draw door handle block
Rectangle rgDHM = new Rectangle((WIDTH / (WIDTH / 4)), (WIDTH / (WIDTH / 4)));
rgDHM.setTranslateX(WIDTH - rgDHM.getWidth() * 2);
rgDHM.setTranslateY(HEIGHT / 2 - rgDHM.getHeight() / 2);
rgDHM.setFill(Color.web("bfbfbf"));
this.getChildren().add(rgDHM);
// Draw door handle
Rectangle rgDHL = new Rectangle((WIDTH / (WIDTH / 8)), (WIDTH / (WIDTH / 2)));
rgDHL.setTranslateX(WIDTH - rgDHL.getWidth() * 2);
rgDHL.setTranslateY(HEIGHT / 2 - rgDHL.getHeight() / 2);
rgDHL.setFill(Color.web("a5a5a5"));
this.getChildren().add(rgDHL);
}
示例9: doorOpen
import javafx.scene.shape.Rectangle; //导入方法依赖的package包/类
public void doorOpen() {
// Draw trim
Rectangle rgDT = new Rectangle(WIDTH, HEIGHT);
rgDT.setFill(Color.TRANSPARENT);
rgDT.setStroke(Color.web("4d2626"));
rgDT.setStrokeWidth((WIDTH / (WIDTH / 2)));
this.getChildren().add(rgDT);
// Draw three hinges
VBox vbHinges = new VBox(WIDTH / 3);
Rectangle rgDH1 = new Rectangle((WIDTH / (WIDTH / 2)), (HEIGHT / (HEIGHT / 8)));
rgDH1.setFill(Color.web("a5a5a5"));
Rectangle rgDH2 = new Rectangle((WIDTH / (WIDTH / 2)), (HEIGHT / (HEIGHT / 8)));
rgDH2.setFill(Color.web("a5a5a5"));
Rectangle rgDH3 = new Rectangle((WIDTH / (WIDTH / 2)), (HEIGHT / (HEIGHT / 8)));
rgDH3.setFill(Color.web("a5a5a5"));
vbHinges.getChildren().addAll(rgDH1, rgDH2, rgDH3);
vbHinges.setTranslateX(rgDH1.getWidth() / 2);
vbHinges.setTranslateY(rgDH1.getHeight());
this.getChildren().add(vbHinges);
// Draw door
Rectangle rgDD = new Rectangle(WIDTH - (WIDTH / (WIDTH / 4)) , HEIGHT);
rgDD.setTranslateX((WIDTH / (WIDTH / 2)) - rgDD.getWidth());
rgDD.setTranslateY((HEIGHT / (HEIGHT / 2)) / 2);
rgDD.setFill(Color.web("673232"));
this.getChildren().add(rgDD);
}
示例10: ParallelTransitionSample
import javafx.scene.shape.Rectangle; //导入方法依赖的package包/类
public ParallelTransitionSample() {
super(400,150);
// create rectangle
Rectangle rect = new Rectangle(-25,-25,50, 50);
rect.setArcHeight(15);
rect.setArcWidth(15);
rect.setFill(Color.CRIMSON);
rect.setTranslateX(50);
rect.setTranslateY(75);
getChildren().add(rect);
// create parallel transition to do all 4 transitions at the same time
parallelTransition = ParallelTransitionBuilder.create()
.node(rect)
.children(
FadeTransitionBuilder.create()
.duration(Duration.seconds(3))
.node(rect)
.fromValue(1)
.toValue(0.3)
.autoReverse(true)
.build(),
TranslateTransitionBuilder.create()
.duration(Duration.seconds(2))
.fromX(50)
.toX(350)
.cycleCount(2)
.autoReverse(true)
.build(),
RotateTransitionBuilder.create()
.duration(Duration.seconds(3))
.byAngle(180)
.cycleCount(4)
.autoReverse(true)
.build(),
ScaleTransitionBuilder.create()
.duration(Duration.seconds(2))
.toX(2)
.toY(2)
.cycleCount(2)
.autoReverse(true)
.build()
)
.cycleCount(Timeline.INDEFINITE)
.autoReverse(true)
.build();
}
示例11: ScaleSample
import javafx.scene.shape.Rectangle; //导入方法依赖的package包/类
public ScaleSample() {
super(180,180);
// simple rectangle
Rectangle rect1 = new Rectangle(0, 25, 25, 25);
rect1.setArcHeight(15);
rect1.setArcWidth(15);
rect1.setFill(Color.WHITE);
rect1.setStroke(Color.DODGERBLUE);
rect1.setStrokeWidth(3);
Polygon arrow = createArrow();
arrow.setLayoutX(46);
arrow.setLayoutY(22);
arrow.setRotate(90);
// simple rectangle with scale 2 in X axis and 0.5 in Y
Rectangle rect2 = new Rectangle(95, 25, 25, 25);
rect2.setArcHeight(15);
rect2.setArcWidth(15);
rect2.setFill(Color.WHITE);
rect2.setStroke(Color.DODGERBLUE);
rect2.setStrokeWidth(3);
rect2.setScaleX(2);
rect2.setScaleY(0.5);
// rectangle with adjustable scale
Rectangle rect3 = new Rectangle(40, 130, 25, 25);
rect3.setArcHeight(15);
rect3.setArcWidth(15);
rect3.setFill(Color.WHITE);
rect3.setStroke(Color.DODGERBLUE);
rect3.setStrokeWidth(3);
rect3.setScaleX(6);
rect3.setScaleY(0.5);
rect3.setTranslateX(rect3.getTranslateX()+30);
//getChildren().addAll(rect1, rect2, rect3);
getChildren().addAll(rect1, arrow, rect2, rect3);
// REMOVE ME
setControls(
new SimplePropertySheet.PropDesc("Scale X", rect3.scaleXProperty(), 0.1d, 16d),
new SimplePropertySheet.PropDesc("Scale Y", rect3.scaleYProperty(), 0.1d, 4d)
);
// END REMOVE ME
}
示例12: doorHalf
import javafx.scene.shape.Rectangle; //导入方法依赖的package包/类
public void doorHalf() {
// Draw trim
Rectangle rgDT = new Rectangle(WIDTH, HEIGHT);
rgDT.setFill(Color.TRANSPARENT);
rgDT.setStroke(Color.web("4d2626"));
rgDT.setStrokeWidth((WIDTH / (WIDTH / 2)));
this.getChildren().add(rgDT);
// Draw three hinges
VBox vbHinges = new VBox(WIDTH / 3);
Rectangle rgDH1 = new Rectangle((WIDTH / (WIDTH / 2)), (HEIGHT / (HEIGHT / 8)));
rgDH1.setFill(Color.web("a5a5a5"));
Rectangle rgDH2 = new Rectangle((WIDTH / (WIDTH / 2)), (HEIGHT / (HEIGHT / 8)));
rgDH2.setFill(Color.web("a5a5a5"));
Rectangle rgDH3 = new Rectangle((WIDTH / (WIDTH / 2)), (HEIGHT / (HEIGHT / 8)));
rgDH3.setFill(Color.web("a5a5a5"));
vbHinges.getChildren().addAll(rgDH1, rgDH2, rgDH3);
vbHinges.setTranslateX(rgDH1.getWidth() / 2);
vbHinges.setTranslateY(rgDH1.getHeight());
this.getChildren().add(vbHinges);
// Draw door
Rectangle rgDD = new Rectangle((WIDTH / (WIDTH / 2)) , HEIGHT);
rgDD.setTranslateX((WIDTH / (WIDTH / 2)) - rgDD.getWidth());
rgDD.setTranslateY((HEIGHT / (HEIGHT / 2)) / 2);
rgDD.setFill(Color.web("673232"));
this.getChildren().add(rgDD);
// Draw door handle block
Rectangle rgDHM = new Rectangle((WIDTH / (WIDTH / 2)), (WIDTH / (WIDTH / 4)));
rgDHM.setTranslateX(rgDD.getX() - rgDD.getWidth());
rgDHM.setTranslateY(rgDD.getY() + rgDD.getHeight() / 2 - rgDHM.getHeight() / 2);
rgDHM.setFill(Color.web("bfbfbf"));
this.getChildren().add(rgDHM);
// Draw door handle
Rectangle rgDHL = new Rectangle((WIDTH / (WIDTH / 2)), (WIDTH / (WIDTH / 2)));
rgDHL.setTranslateX(rgDD.getX() - rgDHL.getWidth() - rgDD.getWidth());
rgDHL.setTranslateY(rgDD.getY() + rgDD.getHeight() / 2 - rgDHL.getHeight() / 2);
rgDHL.setFill(Color.web("a5a5a5"));
this.getChildren().add(rgDHL);
}
示例13: SequentialTransitionSample
import javafx.scene.shape.Rectangle; //导入方法依赖的package包/类
public SequentialTransitionSample() {
super(400,100);
// create rectangle
Rectangle rect = new Rectangle(-25,-25,50, 50);
rect.setArcHeight(15);
rect.setArcWidth(15);
rect.setFill(Color.CRIMSON);
rect.setTranslateX(50);
rect.setTranslateY(50);
getChildren().add(rect);
// create 4 transitions
FadeTransition fadeTransition =
FadeTransitionBuilder.create()
.duration(Duration.seconds(1))
.fromValue(1)
.toValue(0.3)
.cycleCount(2)
.autoReverse(true)
.build();
TranslateTransition translateTransition =
TranslateTransitionBuilder.create()
.duration(Duration.seconds(2))
.fromX(50)
.toX(375)
.cycleCount(2)
.autoReverse(true)
.build();
RotateTransition rotateTransition =
RotateTransitionBuilder.create()
.duration(Duration.seconds(2))
.byAngle(180)
.cycleCount(4)
.autoReverse(true)
.build();
ScaleTransition scaleTransition =
ScaleTransitionBuilder.create()
.duration(Duration.seconds(2))
.toX(2)
.toY(2)
.cycleCount(2)
.autoReverse(true)
.build();
// create sequential transition to do 4 transitions one after another
sequentialTransition = SequentialTransitionBuilder.create()
.node(rect)
.children(fadeTransition, translateTransition, rotateTransition,
scaleTransition)
.cycleCount(Timeline.INDEFINITE)
.autoReverse(true)
.build();
}
示例14: doorHalf
import javafx.scene.shape.Rectangle; //导入方法依赖的package包/类
public void doorHalf() {
// Draw trim
Rectangle rgDT = new Rectangle(WIDTH, HEIGHT);
rgDT.setFill(Color.TRANSPARENT);
rgDT.setStroke(Color.web("4d2626"));
rgDT.setStrokeWidth((WIDTH / (WIDTH / 2)));
this.getChildren().add(rgDT);
// Draw three hinges
VBox vbHinges = new VBox(WIDTH / 3);
Rectangle rgDH1 = new Rectangle((WIDTH / (WIDTH / 2)), (HEIGHT / (HEIGHT / 8)));
rgDH1.setFill(Color.web("a5a5a5"));
Rectangle rgDH2 = new Rectangle((WIDTH / (WIDTH / 2)), (HEIGHT / (HEIGHT / 8)));
rgDH2.setFill(Color.web("a5a5a5"));
Rectangle rgDH3 = new Rectangle((WIDTH / (WIDTH / 2)), (HEIGHT / (HEIGHT / 8)));
rgDH3.setFill(Color.web("a5a5a5"));
vbHinges.getChildren().addAll(rgDH1, rgDH2, rgDH3);
vbHinges.setTranslateX(rgDH1.getWidth() / 2);
vbHinges.setTranslateY(rgDH1.getHeight());
this.getChildren().add(vbHinges);
// Draw door
Rectangle rgDD = new Rectangle((WIDTH / (WIDTH / 2)), HEIGHT);
rgDD.setTranslateX((WIDTH / (WIDTH / 2)) - rgDD.getWidth());
rgDD.setTranslateY((HEIGHT / (HEIGHT / 2)) / 2);
rgDD.setFill(Color.web("673232"));
this.getChildren().add(rgDD);
// Draw door handle block
Rectangle rgDHM = new Rectangle((WIDTH / (WIDTH / 2)), (WIDTH / (WIDTH / 4)));
rgDHM.setTranslateX(rgDD.getX() - rgDD.getWidth());
rgDHM.setTranslateY(rgDD.getY() + rgDD.getHeight() / 2 - rgDHM.getHeight() / 2);
rgDHM.setFill(Color.web("bfbfbf"));
this.getChildren().add(rgDHM);
// Draw door handle
Rectangle rgDHL = new Rectangle((WIDTH / (WIDTH / 2)), (WIDTH / (WIDTH / 2)));
rgDHL.setTranslateX(rgDD.getX() - rgDHL.getWidth() - rgDD.getWidth());
rgDHL.setTranslateY(rgDD.getY() + rgDD.getHeight() / 2 - rgDHL.getHeight() / 2);
rgDHL.setFill(Color.web("a5a5a5"));
this.getChildren().add(rgDHL);
}