1

我的e4 javafx应用程序在显示主窗口之前显示登录对话框。

LifeCycleManager 类

@PostContextCreate
void postContextCreate(Application app, IEclipseContext econtext){  

    //display login dialog extends org.eclipse.fx.ui.dialogs.TitleAreaDialog
    LoginDialog dialog = new LoginDialog(null, "Login", "Login title", "Message", "");
    int response = dialog.open();             

    if (response != Dialog.OK_BUTTON) {
         System.exit(0);
    }
    ....
}

Dialog 具有默认的 javafx 样式(modena)。

如何获取当前主题并应用于此对话框?

4

2 回答 2

1

我发现了如何从当前主题中获取样式表

import org.eclipse.fx.ui.services.theme.ThemeManager;

@Inject
ThemeManager themeManager;

ObservableList<URL> stylesheets =  themeManager.getCurrentTheme().getStylesheetURL();

接下来是创建虚拟阶段并向其添加样式表;

Scene scene = new Scene(new HBox());
Stage stage = new Stage;
stage.setScene(scene);
for (URL url : stylesheets) 
{
    stage.getScene().getStylesheets().add(url.toExternalForm());
}

然后将舞台设置为父窗口(第一个参数)到对话框

LoginDialog dialog = new LoginDialog(stage, "Login", "Login title",
                  "Message", "");

对话框将从父阶段复制样式表并将它们添加到自己的阶段。

有用。但我怀疑这是一种“正确”的方式。必须有其他解决方案。

于 2015-03-26T12:28:13.510 回答
0

您可以通过调用为组件设置默认样式集:

getStylesheets().add(new File("conf/application.css").toURI().toURL().toExternalForm());

你试过这个吗?

于 2015-03-26T08:55:29.087 回答