I am attempting to display a list of errors in the expandableContent area of a DialogPane. To achieve this I am using an Accordian with Titled Panes. If the user wants to view an exception stacktrace they can expand the title pane to view the details.
The difficulty I am encountering is that the dialog doesn't resize when the accordian is expanded.
I have tried adding the following as per https://stackoverflow.com/a/31208445/4931921 without success:
tp1.expandedProperty().addListener( (obs, oldValue, newValue) -> {
Platform.runLater( () -> {
tp1.requestLayout();
tp1.getScene().getWindow().sizeToScene();
} );
} );
Here is an example:
import java.io.PrintWriter;
import java.io.StringWriter;
import javafx.application.Application;
import javafx.scene.control.Accordion;
import javafx.scene.control.ButtonType;
import javafx.scene.control.Dialog;
import javafx.scene.control.DialogPane;
import javafx.scene.control.TextArea;
import javafx.scene.control.TitledPane;
import javafx.stage.Stage;
public class AccordianTest extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Dialog dialog = new Dialog();
DialogPane pane = new DialogPane();
pane.setHeaderText( "Test" );
pane.getButtonTypes().add( ButtonType.OK );
dialog.setDialogPane( pane );
Accordion accordian = new Accordion();
TitledPane tp1 = new TitledPane();
accordian.getPanes().add(tp1);
tp1.setText("My TitledPane");
TextArea ta = new TextArea();
ta.setText( getStackTrace() );
tp1.setContent( ta );
tp1.expandedProperty().addListener( (obs, oldValue, newValue) -> {
Platform.runLater( () -> {
tp1.requestLayout();
tp1.getScene().getWindow().sizeToScene();
} );
} );
pane.setExpandableContent(accordian);
dialog.showAndWait();
}
public static void main(String[] args) {
launch(args);
}
private String getStackTrace(){
StringWriter sw = new StringWriter();
new RuntimeException().printStackTrace( new PrintWriter( sw ) );
return sw.toString();
}
}
The following is what I would like to achieve (I have to resize the dialog manually to get this):