我的 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)。
如何获取当前主题并将其应用于此对话框?
最佳答案
我找到了如何从当前主题中获取样式表
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());
}
然后将stage设置为dialog的父窗口(第一个参数)
LoginDialog dialog = new LoginDialog(stage, "Login", "Login title",
"Message", "");
Dialog 将从父阶段复制样式表并将它们添加到自己的阶段。
它有效。但我怀疑这是一种“正确”的方式。必须有其他解决方案。
关于java - e4-Javafx : How to apply current theme to login dialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29255591/