Friday, January 4, 2013

Implement vertical label by calling setRotate() of Node

javafx.scene.Node class of JavaFX provide a setRotate(double value) method to sets the value of the property rotate.

Note that because the pivot point is computed as the center of this Node's layout bounds, any change to the layout bounds will cause the pivot point to change, which can move the object.

Example:



package javafxui;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.HBox;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
/**
 *
 * @web http://java-buddy.blogspot.com/
 */
public class JavaFXUI extends Application {
 
 @Override
 public void start(Stage primaryStage) {
 Button btn = new Button();
 btn.setText("Say 'Hello World'");
 btn.setOnAction(new EventHandler<ActionEvent>() {
 @Override
 public void handle(ActionEvent event) {
 System.out.println("Hello World!");
 }
 });
 
 btn.setRotate(45);
 btn.setTranslateY(100);
 
 HBox hBox = new HBox();
 Label verticalLabel = new Label("java-buddy");
 verticalLabel.setRotate(270);
 verticalLabel.setTranslateY(100);
 hBox.getChildren().addAll(verticalLabel, btn);
 
 StackPane root = new StackPane();
 root.getChildren().add(hBox);
 
 Scene scene = new Scene(root, 300, 250);
 
 primaryStage.setTitle("java-buddy.blogspot.com");
 primaryStage.setScene(scene);
 primaryStage.show();
 }
 public static void main(String[] args) {
 launch(args);
 }
}


No comments:

Post a Comment

[フレーム]

Subscribe to: Post Comments (Atom)

AltStyle によって変換されたページ (->オリジナル) /