I want use WPF on Windows version of my java application. I found it is easy to do it with SWT and it is also supporting wpf ResourceDictionary XAML for SWT elements (please see this). SWT WPF implementation working well for me but I couldn’t find out how I can put WPF theme on it. Some of SWT widgets same org.eclipse.swt.widgets.Button have setData method but some of them like org.eclipse.swt.widgets.Display have not that method. Also setDate method on shell will not set theme on entire window.
So how can I put a theme for entire window of my SWT WPF program?
Here is a sample code:
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. So it is better to not be used.