2015-03-25 21 views
1

我的e4 javafx应用程序在显示主窗口之前显示登录对话框。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); 
    } 
    .... 
} 

对话框有默认的JavaFX样式(摩德纳)。

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

回答

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", ""); 

对话框将来自父系的阶段复制样式表,将它们添加到自己的舞台。

它的工作原理。但我怀疑这是一种“适当”的方式。必须有其他解决方案。

0

你可以通过调用设置的成分中的默认样式集:

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

你试试这个?

+0

在我的情况下,我不想从特定文件添加样式表。我需要从当前主题(可以是其中的许多主题)中获取样式表,并将它们(样式表)添加到对话阶段。 – 2015-03-26 12:08:28

相关问题