【发布时间】:2016-04-12 18:51:14
【问题描述】:
我正在尝试在 DialogPane 的可扩展内容区域中显示错误列表。为了实现这一点,我正在使用带有 Titled Panes 的 Accordian。如果用户想要查看异常堆栈跟踪,他们可以展开标题窗格以查看详细信息。
我遇到的困难是展开手风琴时对话框没有调整大小。
我已尝试按照https://stackoverflow.com/a/31208445/4931921 添加以下内容,但未成功:
tp1.expandedProperty().addListener( (obs, oldValue, newValue) -> {
Platform.runLater( () -> {
tp1.requestLayout();
tp1.getScene().getWindow().sizeToScene();
} );
} );
这是一个例子:
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();
}
}
以下是我想要实现的(我必须手动调整对话框的大小才能得到它):
【问题讨论】:
标签: javafx