如何在Eclipse CSS样式中排除对话框Shell?
Hey Glen, let's tackle this styling issue you're facing—getting that clean white background for your views, panels, and toolbars while keeping dialogs looking native across different operating systems is totally doable with more targeted CSS selectors. Here are a few solid approaches:
1. Target the E4 Main Window Explicitly
E4 automatically adds a unique CSS class to your application's main window: .e4-main-window. You can use this to apply your white background only to the main UI, leaving dialogs untouched:
.e4-main-window { background-color: white; }
This works because dialog shells don't have the e4-main-window class, so they'll retain their default system styling. It's the cleanest way to avoid messing with dialogs entirely.
2. Style Specific UI Components Directly
If you want even more control (e.g., only certain parts of the main UI need white backgrounds), target the E4-specific components instead of the global Shell:
/* Style view/editor containers */ MPartStack, CTabFolder { background-color: white; } /* Style individual views/editors */ MPart { background-color: white; } /* Style toolbars */ ToolBar { background-color: white; }
By focusing on the exact components you care about (like MPart for views, ToolBar for toolbars), you completely avoid affecting dialog shells and their content.
3. Make Dialog Styling Portable (If You Need to Adjust Them)
If you still want to tweak dialog backgrounds but need cross-OS compatibility, use SWT's built-in system color variables instead of hardcoding hex values. These variables pull the native OS colors automatically:
Shell[style~='SWT.APPLICATION_MODAL'] { background-color: swt-color-dialog-background; }
swt-color-dialog-background will match the default dialog background of whatever OS your app is running on, so you don't have to worry about mismatched styles on Windows, macOS, or Linux.
Final Recommendation
Stick with approach #1 or #2 first—they're the most reliable and won't interfere with native dialog behavior. Only use approach #3 if you specifically need to adjust dialog styling while keeping things portable.
内容的提问来源于stack exchange,提问作者Link19

