當前位置: 首頁>>代碼示例>>Java>>正文


Java StackPane.setTranslateX方法代碼示例

本文整理匯總了Java中javafx.scene.layout.StackPane.setTranslateX方法的典型用法代碼示例。如果您正苦於以下問題:Java StackPane.setTranslateX方法的具體用法?Java StackPane.setTranslateX怎麽用?Java StackPane.setTranslateX使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javafx.scene.layout.StackPane的用法示例。


在下文中一共展示了StackPane.setTranslateX方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: init

import javafx.scene.layout.StackPane; //導入方法依賴的package包/類
private void init(Stage primaryStage) {
    Group root = new Group();
    primaryStage.setResizable(false);
    primaryStage.setScene(new Scene(root, 260,100));
    //create a circle with effect
    final Circle circle = new Circle(20,  Color.rgb(156,216,255));
    circle.setEffect(new Lighting());
    //create a text inside a circle
    final Text text = new Text (i.toString());
    text.setStroke(Color.BLACK);
    //create a layout for circle with text inside
    final StackPane stack = new StackPane();
    stack.getChildren().addAll(circle, text);
    stack.setLayoutX(30);
    stack.setLayoutY(30);

    //create a timeline for moving the circle

    timeline = new Timeline();
    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.setAutoReverse(true);

    //one can add a specific action when each frame is started. There are one or more frames during
    // executing one KeyFrame depending on set Interpolator.
    timer = new AnimationTimer() {
        @Override
        public void handle(long l) {
            text.setText(i.toString());
            i++;
        }

    };

    //create a keyValue with factory: scaling the circle 2times
    KeyValue keyValueX = new KeyValue(stack.scaleXProperty(), 2);
    KeyValue keyValueY = new KeyValue(stack.scaleYProperty(), 2);

    //create a keyFrame, the keyValue is reached at time 2s
    Duration duration = Duration.seconds(2);
    //one can add a specific action when the keyframe is reached
    EventHandler<ActionEvent> onFinished = new EventHandler<ActionEvent>() {
        public void handle(ActionEvent t) {
             stack.setTranslateX(java.lang.Math.random()*200);
             //reset counter
             i = 0;
        }
    };

    KeyFrame keyFrame = new KeyFrame(duration, onFinished , keyValueX, keyValueY);

    //add the keyframe to the timeline
    timeline.getKeyFrames().add(keyFrame);

    root.getChildren().add(stack);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:56,代碼來源:TimelineEvents.java

示例2: TimelineEventsSample

import javafx.scene.layout.StackPane; //導入方法依賴的package包/類
public TimelineEventsSample() {
    super(70,70);
    //create a circle with effect
    final Circle circle = new Circle(20,  Color.rgb(156,216,255));
    circle.setEffect(new Lighting());
    //create a text inside a circle
    final Text text = new Text (i.toString());
    text.setStroke(Color.BLACK);
    //create a layout for circle with text inside
    final StackPane stack = new StackPane();
    stack.getChildren().addAll(circle, text);
    stack.setLayoutX(30);
    stack.setLayoutY(30);

    //create a timeline for moving the circle

    timeline = new Timeline();
    timeline.setCycleCount(Timeline.INDEFINITE);
    timeline.setAutoReverse(true);

    //one can add a specific action when each frame is started. There are one or more frames during
    // executing one KeyFrame depending on set Interpolator.
    timer = new AnimationTimer() {
        @Override
        public void handle(long l) {
            text.setText(i.toString());
            i++;
        }

    };

    //create a keyValue with factory: scaling the circle 2times
    KeyValue keyValueX = new KeyValue(stack.scaleXProperty(), 2);
    KeyValue keyValueY = new KeyValue(stack.scaleYProperty(), 2);

    //create a keyFrame, the keyValue is reached at time 2s
    Duration duration = Duration.seconds(2);
    //one can add a specific action when the keyframe is reached
    EventHandler<ActionEvent> onFinished = new EventHandler<ActionEvent>() {
        public void handle(ActionEvent t) {
             stack.setTranslateX(java.lang.Math.random()*200-100);
             //reset counter
             i = 0;
        }
    };

    KeyFrame keyFrame = new KeyFrame(duration, onFinished , keyValueX, keyValueY);

    //add the keyframe to the timeline
    timeline.getKeyFrames().add(keyFrame);

    getChildren().add(stack);
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:54,代碼來源:TimelineEventsSample.java

示例3: createTraceWidget

import javafx.scene.layout.StackPane; //導入方法依賴的package包/類
private Pane createTraceWidget(ITraceExtractor<Step<?>, State<?,?>, TracedObject<?>, Dimension<?>, Value<?>> extractor, String label, ReadOnlyDoubleProperty width) {
	final Pane pane = new Pane();
	pane.setBackground(TRANSPARENT_BACKGROUND);
	final Rectangle rectangle = new Rectangle(0, 0, 0, 12);
	rectangle.setFill(Color.LIGHTGRAY);
	rectangle.widthProperty().bind(width.subtract(10));
	rectangle.setArcHeight(12);
	rectangle.setArcWidth(12);
	Label text = new Label(label);
	text.setTextOverrun(OverrunStyle.ELLIPSIS);
	text.setAlignment(Pos.CENTER);
	text.setMouseTransparent(true);
	text.setTextFill(Color.WHITE);
	text.setFont(FONT);
	text.setMaxWidth(0);
	text.maxWidthProperty().bind(rectangle.widthProperty());
	StackPane layout = new StackPane();
	layout.getChildren().addAll(rectangle, text);
	pane.getChildren().add(layout);
	layout.setTranslateY(13);
	layout.setTranslateX(5);
	pane.setPrefHeight(25);
	pane.setMinHeight(25);
	pane.setMaxHeight(25);

	final Shape arrow1 = createCursor();
	final Shape arrow2 = createCursor();
	arrow1.setTranslateX(5);
	arrow1.setTranslateY(4);
	arrow2.translateXProperty().bind(rectangle.widthProperty().add(5));
	arrow2.setTranslateY(4);
	pane.getChildren().add(arrow1);
	pane.getChildren().add(arrow2);
	
	return pane;
}
 
開發者ID:eclipse,項目名稱:gemoc-studio-modeldebugging,代碼行數:37,代碼來源:TraceSectionsDialog.java

示例4: VertexView

import javafx.scene.layout.StackPane; //導入方法依賴的package包/類
public VertexView(final int stateIndex, StateVertex vertex) {
	circle = new Circle(RADIUS);
	circle.setFill(Color.SLATEBLUE);

	this.stateIndex = stateIndex;

	final String s = vertex.getTooltip();
	final Tooltip t = new Tooltip(s);
	Tooltip.install(this, t);
	vertex.setOnTooltipUpdateCommand(text -> Platform.runLater(() -> t.setText(text)));

	label = new Label(computeStateLabel(this.stateIndex));
	label.setTextOverrun(OverrunStyle.ELLIPSIS);
	label.setAlignment(Pos.CENTER);
	label.setMouseTransparent(true);
	label.setTextFill(Color.WHITE);
	label.setFont(STATE_INDEX_FONT);
	label.setMaxWidth(RADIUS * 2);
	StackPane layout = new StackPane();
	layout.getChildren().addAll(circle, label);
	layout.setTranslateX(-RADIUS);
	layout.setTranslateY(-RADIUS);

	getChildren().add(layout);

	setOnMousePressed(event -> {
		circle.setCursor(Cursor.MOVE);
		mouseX = event.getX();
		mouseY = event.getY();
		event.consume();
	});

	setOnMouseReleased(event -> {
		setCursor(Cursor.DEFAULT);
	});

	setOnMouseDragged(event -> {
		double deltaX = event.getX() - mouseX;
		double deltaY = event.getY() - mouseY;
		setTranslateX(getTranslateX() + deltaX);
		setTranslateY(getTranslateY() + deltaY);
		event.consume();
	});

	setOnMouseEntered(event -> circle.setEffect(GLOW));
	setOnMouseExited(event -> circle.setEffect(null));
}
 
開發者ID:eclipse,項目名稱:gemoc-studio-modeldebugging,代碼行數:48,代碼來源:VertexView.java


注:本文中的javafx.scene.layout.StackPane.setTranslateX方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。