Ho uno stage con un elenco variabile di caselle di controllo. Quando l'elenco cambia, lo stage deve essere ridimensionato. Funziona bene in molte occasioni, dopo aver aggiunto tutte le caselle di controllo a un VBox, quindi chiama stage.sizeToScene() e lo stage viene ridimensionato di conseguenza. Tuttavia, se si inserisce tutto questo in una scheda all'interno di una tabella, stage.sizeToScene() non funziona più. Sono un po 'bloccato perché questo è. Qualcuno ha un buon lavoro o soluzione?JavaFX TabPane e ridimensionamento fase padre
Alcuni esempi di codice sono di seguito. Basta cambiare il campo withTabs con false o true, per mostrare la situazione senza e con un TabPane.
Grazie per l'aiuto.
import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.ComboBox;
import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class TabResizeError extends Application {
boolean withTabs=false;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("Hello World!");
//holds variable number of check boxes
VBox channelBox=new VBox();
channelBox.setSpacing(5);
//create controls
HBox controlsHBox=new HBox();
controlsHBox.setSpacing(5);
Button btn = new Button();
btn.setText("Resize Test");
ComboBox<Integer> comboBox=new ComboBox<Integer>();
ObservableList<Integer> number=FXCollections.observableArrayList();
for (int i=0; i<32; i++){
number.add(i);
}
comboBox.setItems(number);
comboBox.getSelectionModel().select(5);
controlsHBox.getChildren().addAll(btn, comboBox);
btn.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
//remove all check boxes
channelBox.getChildren().removeAll(channelBox.getChildren());
//add new check boxes
for (int i=0; i<comboBox.getSelectionModel().getSelectedItem(); i++){
CheckBox checkBox=new CheckBox(("Channel "+i));
channelBox.getChildren().add(checkBox);
}
primaryStage.sizeToScene();
}
});
Pane root=null;
VBox mainPane = new VBox();
mainPane.getChildren().addAll(controlsHBox,channelBox);
mainPane.setSpacing(5);
if (withTabs){
TabPane tabbedPane=new TabPane();
Tab tab=new Tab("TestTab");
tab.setContent(mainPane);
tabbedPane.getTabs().add(tab);
root=new BorderPane(tabbedPane);
}
else{
root = mainPane;
}
// root.setTop(controlsHBox);
// root.setCenter(channelBox);
primaryStage.setScene(new Scene(root));
primaryStage.setMinHeight(300);
primaryStage.show();
}
}
Grazie mille! Apprezzo comunque la risposta: sempre utile per gli altri a leggere. – macster110