2013-09-04 3 views

답변

7

회전이 방법은 다른 해결책이 없습니다.

rotated

샘플 코드 :

import javafx.application.Application; 
import javafx.geometry.Pos; 
import javafx.scene.*; 
import javafx.scene.control.*; 
import javafx.scene.layout.StackPane; 
import javafx.stage.Stage; 

/* Displays a button with it's text rotated 90 degrees to the left */ 
public class RotatedText extends Application { 
    @Override public void start(Stage stage) { 
     Button feedbackButton = createButtonWithRotatedText("Feedback Form"); 

     StackPane layout = new StackPane(); 
     layout.getChildren().setAll(feedbackButton); 
     StackPane.setAlignment(feedbackButton, Pos.TOP_RIGHT); 
     layout.setPrefSize(225, 275); 
     layout.setStyle("-fx-background-color: lightcyan;"); 

     stage.setScene(new Scene(layout)); 
     stage.show(); 
    } 

    private Button createButtonWithRotatedText(String text) { 
     Button button = new Button(); 
     Label label = new Label(text); 
     label.setRotate(-90); 
     button.setGraphic(new Group(label)); 

     // in-line css just used for sample purposes, 
     // usually you would apply a stylesheet. 
     button.setStyle(
       "-fx-base: orange; " + 
       "-fx-font-size: 30px; " + 
       "-fx-text-background-color: whitesmoke;" 
     ); 

     return button; 
    } 

    public static void main(String[] args) { launch(args); } 
} 
+0

무엇입니까의 이익을'button.setGraphic (새 그룹 (라벨))''button.setGraphic (라벨) '를 통해? – c0der

+0

시도해보고 C0der를 참조하십시오. 그룹으로 묶는다면 원하는 결과를 얻을 수 있습니다. 그룹으로 묶지 않으면 왜곡 된 엉망이 생깁니다. 이는 [그룹] (https://docs.oracle.com/javase/9/docs/api/javafx/scene/Group.html) (다른 노드 유형과 다릅니다)에서 레이아웃이 작동하는 방식 때문입니다. "if 변형 및 효과는이 그룹의 자식에게 직접 설정되며이 그룹의 레이아웃 범위에 포함됩니다. " – jewelsea

관련 문제