![](/img/trans.png)
[英]Changing the orientation (portrait or landscape) of an Excel chart using VBA
[英]Javafx - Rotate node for display in landscape/portrait orientation on handheld device
我正在開發的javafx應用程序最終將在分辨率為800x480的手持設備上運行。 該應用程序通常將以縱向模式運行,但是對於某些功能(例如,顯示圖表和表格),將需要切換到橫向模式以更好地顯示數據。
我的問題是,是否有直接的方法來操作以90度的倍數旋轉的節點?
我可以通過調用setRotate()來旋轉表,盡管這引入了幾個新問題:
要在旋轉時調整列寬的大小,用戶必須將列分隔符從左向右拖動(與標題行垂直),表格仍然將其寬度/高度擴展到其父級的大小,盡管這樣做不起作用旋轉-90度(或90的其他倍數)時。
另一個約束是,圖表內容包含在BorderPane的中心,BorderPane的頂部和底部包含工具欄,這會阻止旋轉整個場景。
這是我的SSCCE; 如果下面的代碼有任何問題,請糾正我。
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.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TablePanelTrial extends Application {
BorderPane root = new BorderPane();
private boolean isRotated=false;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(final Stage primaryStage) {
primaryStage.setTitle("Table Panel Trial");
final TablePanel tp = new TablePanel();
Button btnRotate = new Button("Rotate");
btnRotate.setOnAction(new EventHandler() {
@Override
public void handle(ActionEvent event) {
double r = -90;
if(isRotated){
r=0;
isRotated = !isRotated;
}
else{
r=-90;
tp.tv.setMinHeight(200);
isRotated = !isRotated;
}
tp.rotate(r);
}
});
root.setTop(btnRotate);
root.setCenter(tp.getVB());
primaryStage.setScene(new Scene(root, 480, 800));
primaryStage.show();
}
class TablePanel{
private VBox vbox = new VBox();
private TableView tv = new TableView();
private String[] labelVal = {"Column 1", "Element", "Difference", "File Name", "Report Number"};
public TablePanel(){
TableColumn column1 = new TableColumn(labelVal[0]);
TableColumn column2 = new TableColumn(labelVal[1]);
TableColumn column3 = new TableColumn(labelVal[2]);
TableColumn column4 = new TableColumn(labelVal[3]);
TableColumn column5 = new TableColumn(labelVal[4]);
tv.getColumns().addAll(column1, column2, column3, column4,column5);
vbox.getChildren().add(tv);
tv.setPrefHeight(2000);
}
public Pane getVB(){
return vbox;
}
public void rotate(double r){
vbox.setRotate(r);
}
}
}
我認為,當設備進入橫向模式時,Android不執行旋轉功能。 必須重新繪制布局才能顯示它。 使用JavaFX,您可以做的是在場景中添加一個偵聽器以偵聽寬度的變化,因為這基本上就是這種情況。 您最有可能這樣做:
scene.widthProperty().addListener((observable, oldValue, newValue) -> {
....initialize the changes to layout here....
);
});
可能不是最好的解決方案,但我想它是對的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.