1

CONSTRAINED_RESIZE_POLICY列サイズ変更ポリシーを使用したTableViewがあります。ウィンドウのサイズを手動で変更するとうまく機能しますが、ウィンドウを最大化するか、最大化された状態から復元すると、列が調整されません。

このような場合に列のサイズが変更されるように、TableViewを強制的に「更新」する方法はありますか?

更新:問題を再現するためのコンパイル可能なコードのサンプル

public class TableViewResizeTest extends Application {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    launch(args);
}

@Override
public void start(Stage primaryStage) {

    primaryStage.setTitle("TableView resize demo");

    ObservableList<Room> roomsList = FXCollections.observableArrayList();

    final TableView rooms = new TableView();
    TableColumn icons = new TableColumn();
    TableColumn name  = new TableColumn("Name");
    TableColumn topic = new TableColumn("Topic");
    TableColumn users = new TableColumn("Users");

    rooms.getColumns().addAll(icons, name, topic, users);

    name.setCellValueFactory( new PropertyValueFactory<Room,String>("name"));
    topic.setCellValueFactory( new PropertyValueFactory<Room,String>("topic"));
    users.setCellValueFactory( new PropertyValueFactory<Room,String>("users"));
    icons.setCellValueFactory( new PropertyValueFactory<Room,String>("icons"));

    name.setMinWidth(50);
    name.setMaxWidth(450);
    topic.setMinWidth(10);
    users.setMinWidth(100);
    users.setMaxWidth(150);

    icons.setMaxWidth(35);
    icons.setMinWidth(35);
    // Room resize policy, this is almost perfect
    rooms.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

    for (int i = 1; i<50; i++) roomsList.add(new Room("Sample Room "+i));
    rooms.setItems(roomsList);
    BorderPane root = new BorderPane();
    root.setCenter(rooms);
    primaryStage.setScene(new Scene(root, 500, 460));
    primaryStage.show();

}

public class Room {

    public Room(String name) {

        this.name = new SimpleStringProperty(name);
        this.topic= new SimpleStringProperty("This is a sample description text");
        this.icon= new SimpleStringProperty("");
        nUsers = (int)(Math.random()*1000);
        this.users= new SimpleStringProperty(nUsers.toString());
    }    

    Integer nUsers;

    private SimpleStringProperty name;
    private SimpleStringProperty topic;
    private SimpleStringProperty users;
    private SimpleStringProperty icon;


    public String getName() {
        return name.get();
    }

    public void setName(String name) {
        this.name.set(name);
    }

    public String getTopic() {
        return topic.get();
    }

    public void setTopic(String topic) {
        this.topic.set(topic);

    }

    public String getUsers() {
        return nUsers.toString();
    }

    public void setUsers(String users) {
        this.users.set(users);
    }


    public String getIcon() {
        return icon.get();
    }

    public void setIcon(String icon) {
        this.icon.set(icon);
    }
}   

}

サイズ変更ポリシーに従って、最後の列「ユーザー」は常に表示されている必要があり、フォームのサイズを手動で変更すると正常に機能します。ただし、最大化と復元を数回実行しようとすると、ウィンドウのサイズを手動で少し変更するまで、ウィンドウが表示されなくなることがわかります。

4

1 に答える 1

1

名前、ユーザー、アイコンの列を最大幅と最小幅の境界で制約し、トピック列が残りの空き領域を占めるようにしたいとします。回避策として、トピック列を列の最後に配置することをお勧めしますrooms.getColumns().addAll(icons, name, users, topic);

于 2012-05-24T09:07:32.713 に答える