java - 如何为我的 SWT WPF 程序设置主题?

标签 java wpf swt

我想在我的 Java 应用程序的 Windows 版本上使用 WPF。我发现使用 SWT 很容易做到这一点,它还支持 SWT 元素的 wpf ResourceDictionary XAML ( please see this )。 SWT WPF 实现对我来说效果很好,但我不知道如何放置 WPF theme在上面。一些与 org.eclipse.swt.widgets.Button 相同的 SWT 小部件具有 setData 方法,但其中一些像 org.eclipse.swt.widgets.Display没有那个方法。 shell 上的 setDate 方法也不会在整个窗口上设置主题。

那么如何为我的 SWT WPF 程序的整个窗口设置一个主题呢?

这是一个示例代码:

import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MenuItem;

public class MainForm {

    protected Shell shell;

    public static void main(String[] args) {
        try {
            MainForm window = new MainForm();
            window.open();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public void open() {
        Display display = Display.getDefault();
        createContents();
        shell.open();
        shell.layout();
        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
    }

    protected void createContents() {
        shell = new Shell();
        shell.setData(
                "ResourceDictionary",
                "ExpressionDark.xaml");
        // theme not applied on entire window, just buttons

        shell.setSize(450, 300);
        shell.setText("Window Title");

        Button button = new Button(shell, SWT.FLAT);
        button.setText("Button");
        button.setSize(250, 50);
        button.setBounds(0, 50, 250, 50);

        Menu menu = new Menu(shell, SWT.BAR);
        shell.setMenuBar(menu);

        MenuItem mntmNewSubmenu = new MenuItem(menu, SWT.CASCADE);
        mntmNewSubmenu.setText("New SubMenu");

        Menu menu_1 = new Menu(mntmNewSubmenu);
        mntmNewSubmenu.setMenu(menu_1);

    }
}

最佳答案

SWT WPF is no longer supported. 所以最好不要用。

关于java - 如何为我的 SWT WPF 程序设置主题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9741252/

相关文章:

java - maven,如何使用其传递依赖项重新打包第 3 方 jar

java记录器从另一个类调用

wpf - 在 xaml 中访问属性背后的代码

c# - 防止在数据网格上添加空白行

java - 使用 SWT 在 Eclipse 插件透视图中加载 BMP

java - 不同类之间的通信(Eclipse Forms 部分之间的通信)

java - 在矩阵中按降序排列数字的边框

java - 将 cURL post 转换为 HTTPclient 和 HttpPost。收到 Http 403 错误。 [JAVA]

c# - 单击 WPF TreeView 时如何更改 TreeViewItem 的背景颜色?

java - SWT 源代码编辑器小部件