2017-01-16 20 views
0

私はVBoxの中にTableViewを持っていて、私はTableViewで取り除くことができない本当にイライラスクロールバーがあります。これを取り除く助けに感謝します。VBox内のテーブルでスクロールバーを削除する方法(JavaFX)

私はTableViewの上に座っているラベルもあるので、基本的に私はVbox内にTableViewを持っています。これを達成する代替提案もすばらしいです。

コード:

private void setFlagTab(Tab FlagTab, String name, ArrayList<Flag> flagList){ 

TableView table = new TableView(); 

ObservableList<Flag> data = FXCollections.observableArrayList(flagList); 


Label label = new Label("Flags identified for: " + name); 
label.setFont(new Font("Arial", 20)); 


TableColumn startCol = new TableColumn("Start Time"); 
startCol.setCellValueFactory(
     new PropertyValueFactory<Flag, String>("startTime")); 

startCol.setSortable(false); 
startCol.prefWidthProperty().bind(table.widthProperty().multiply(0.1)); 

TableColumn endCol = new TableColumn("End Time"); 
endCol.setCellValueFactory(
     new PropertyValueFactory<Flag, String>("endTime")); 

endCol.setSortable(false); 
endCol.prefWidthProperty().bind(table.widthProperty().multiply(0.1)); 

TableColumn phaseCol = new TableColumn("Phase"); 
phaseCol.setCellValueFactory(
     new PropertyValueFactory<Flag, String>("phase")); 

phaseCol.setSortable(false); 
phaseCol.prefWidthProperty().bind(table.widthProperty().multiply(0.2)); 

TableColumn messageCol = new TableColumn("Message"); 
messageCol.setCellValueFactory(
     new PropertyValueFactory<Flag, String>("message")); 

messageCol.setSortable(false); 
messageCol.prefWidthProperty().bind(table.widthProperty().multiply(0.4)); 

TableColumn targetCol = new TableColumn("Target"); 
targetCol.setCellValueFactory(
     new PropertyValueFactory<Flag, String>("target")); 

targetCol.setSortable(false); 
targetCol.prefWidthProperty().bind(table.widthProperty().multiply(0.1)); 

TableColumn actualCol = new TableColumn("Actual"); 
actualCol.setCellValueFactory(
     new PropertyValueFactory<Flag, String>("actual")); 

actualCol.setSortable(false); 
actualCol.prefWidthProperty().bind(table.widthProperty().multiply(0.1)); 



table.setItems(data); 
table.getColumns().addAll(startCol, endCol, phaseCol, messageCol, targetCol, actualCol); 


VBox vbox = new VBox(); 
vbox.setSpacing(5); 
vbox.setPadding(new Insets(10, 0, 0, 10)); 
vbox.getChildren().addAll(label, table); 


    FlagTab.setText("Flags"); 
    FlagTab.setContent(vbox); 
} 

ありがとう!

答えて

0

は、次の例を考えてみましょう:

TableView table = new TableView(); 

TableColumn nameCol = new TableColumn("Name"); 
nameCol.setCellValueFactory(new PropertyValueFactory("name")); 
nameCol.prefWidthProperty().bind(table.widthProperty().multiply(0.4)); 

TableColumn surnameCol = new TableColumn("Surname"); 
surnameCol.setCellValueFactory(new PropertyValueFactory("surname")); 
    surnameCol.prefWidthProperty().bind(table.widthProperty().multiply(0.4)); 

TableColumn ageCol = new TableColumn("Age"); 
ageCol.setCellValueFactory(new PropertyValueFactory("age")); 
ageCol.prefWidthProperty().bind(table.widthProperty().multiply(0.2)); 

table.getColumns().addAll(nameCol, surnameCol, ageCol); 

StackPane root = new StackPane(); 
root.getChildren().add(table); 

Scene scene = new Scene(root, 300, 250); 
primaryStage.setScene(scene); 
primaryStage.show(); 

// Uncomment this line to see the scrollbar 
// table.getItems().add(new Person("John", "Doe", 26)); 

あなたは、水平スクロールバーが表示されますテーブルにいくつかのデータを追加したら、それは、それはそうと、それがあるとして、あなたがそれを実行した場合、正常に動作、しかし奇妙ます。私が知っている2つの回避策があります。

  1. テーブル幅に列をバインドするとき、あなたは、列幅と干渉するしたくない場合はmultiply(0.39)
  2. multiply(0.4)を置き換えることにより、例えば、いくつかの追加のスペースを残してください、そして、あなたがすることを感じます table.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
+0

こんにちは、あなたの答えに感謝:ポリシーのサイズを変更し、この列を設定することで、それを完全に無効にすることができ、水平スクロールバーを必要としません。あなたの最初の回避策は、私がやってきたことです、それは完全に表示されませんが、それは私が見つけた最高のソリューションです。 – Andrew

関連する問題