2016-08-12 1 views
1

독립 실행 형 응용 프로그램에 완전히 새로운 기능입니다. 제발 도와주세요.javafx - tableview 크기를 현재 창 크기로 수정하는 방법

아래와 같이 6 개의 열이있는 TableView가 창에 절반으로 표시됩니다. 윈도우가 확장 되더라도

enter image description here

나는 현재의 창 크기를 수정하려면,의있는 tableview해야 자동 크기 조절. 이 일을 할 수있는 방법이 있습니까?

이것은 일차 스테이지의 높이와 폭에 대한 바람직한 높이와 폭을 결합하여 수행 할 수있는 코드 조각

GridPane tableGrid= new GridPane(); 
tableGrid.setVgap(10); 
tableGrid.setHgap(10); 
Label schoolnameL= new Label(SCHOOL+school_id); 
schoolnameL.setId("schoolLabel"); 
Button exportDataSheetBtn= new Button("Export In File"); 
tableView.setMaxWidth(Region.USE_PREF_SIZE); 
tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY); 
tableGrid.getChildren().addAll(schoolnameL,exportDataSheetBtn,tableView); 
+0

TableView 및 상위 컨테이너와 관련된 일부 코드를 추가하면 더 잘 해결할 수 있습니다. – ItachiUchiha

답변

0

이다. 여기 MCVE입니다 :

import javafx.application.Application; 
import javafx.collections.ObservableList; 
import javafx.scene.Scene; 
import javafx.scene.control.TableView; 
import javafx.stage.Stage; 

public class MCVE extends Application { 

    @Override 
    public void start(Stage stage) { 

     TableView<ObservableList<String>> table = new TableView<ObservableList<String>>(); 

     // We bind the prefHeight- and prefWidthProperty to the height and width of the stage. 
     table.prefHeightProperty().bind(stage.heightProperty()); 
     table.prefWidthProperty().bind(stage.widthProperty()); 

     stage.setScene(new Scene(table, 400, 400)); 
     stage.show(); 
    } 

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

} 
0

당신은 장면의 루트로하여 ScrollPane을 사용하고 그 안에 다른 모든 것들을 넣을 수 있습니다. 그런 다음 setFitToWidth 및 setFitToHeight 속성을 true로 설정하면 ScrollPane 내부의 모든 내용이 ScrollPane 크기에 맞게 늘어나고 ScrollPane은 Layout Pane 이후 Scene에 적합합니다. 사용자가 윈도우의 크기를 minWidth보다 작게 조정하여 내용이 잘리지 않으면 ScrollBars도 표시됩니다!

@Override 
public void start(Stage stage) { 

    TableView<ObservableList<String>> table = new TableView<ObservableList<String>>(); 
    table.setMinWidth(400); 

    ScrollPane sp = new ScrollPane(table); 
    sp.setFitToHeight(true); 
    sp.setFitToWidth(true); 

    stage.setScene(new Scene(table, 800, 600)); 
    stage.show(); 
} 

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

나는 크기 조정이 가능한 GUI를이 post을 확인하기 위해 :) 더 일반적인 팁에 대한

을, 조나단의 대답부터 MCVE의 일부를 복사하면 조나단 마음을 그나마 희망!

관련 문제