A C#/.NET port of the Java SWT (Standard Widget Toolkit) library with multi-platform support
$ dotnet add package SWTSharpA C#/.NET port of the Java SWT (Standard Widget Toolkit) library, providing cross-platform GUI capabilities for .NET applications.
dotnet add package SWTSharp
Or build from source:
git clone https://github.com/jas88/swtsharp
cd swtsharp
dotnet restore
dotnet build
# Install Git hooks (optional but recommended for contributors)
./scripts/install-hooks.sh
using SWTSharp;
// Create display and main window
var display = Display.Default;
var shell = new Shell(display);
shell.Text = "My Application";
shell.SetSize(400, 300);
// Create widgets
var label = new Label(shell, SWT.NONE);
label.Text = "Hello, SWTSharp!";
label.SetBounds(10, 10, 200, 25);
var button = new Button(shell, SWT.PUSH);
button.Text = "Click Me";
button.SetBounds(10, 50, 100, 30);
button.Click += (sender, e) => {
Console.WriteLine("Button clicked!");
};
// Open window and run event loop
shell.Open();
while (!shell.IsDisposed)
{
if (!display.ReadAndDispatch())
display.Sleep();
}
display.Dispose();
| Platform | Status | Implementation | Notes |
|---|---|---|---|
| Windows | ✅ Complete | Win32 API | Full native Win32 widget support |
| macOS | ✅ Complete | Cocoa/AppKit | Native macOS controls with ObjC runtime |
| Linux | ✅ Complete | GTK 3 | Native GTK widgets with X11 display |
All three platforms support:
# Restore dependencies
dotnet restore
# Build library
dotnet build
# Run tests
dotnet test
# Run sample
dotnet run --project samples/SWTSharp.Sample
# Create NuGet package
dotnet pack -c Release
swtsharp/
├── src/
│ └── SWTSharp/ # Main library
│ ├── Platform/ # Platform-specific implementations
│ │ ├── Win32/ # Windows Win32 API
│ │ ├── MacOS/ # macOS Cocoa/AppKit
│ │ ├── Linux/ # Linux GTK
│ │ └── SafeHandles/ # Platform-safe resource handles
│ ├── Events/ # Event handling (19 event types)
│ ├── Layout/ # Layout managers (5 types)
│ ├── Dialogs/ # Standard dialogs (6 types)
│ └── Graphics/ # Graphics and drawing APIs
├── tests/
│ └── SWTSharp.Tests/ # Comprehensive unit tests
├── samples/
│ └── SWTSharp.Sample/ # Example application
└── .github/
└── workflows/ # CI/CD with multi-platform testing
SWTSharp follows the Java SWT API design with C# conventions:
Button, Shell)shell.Text instead of shell.getText())The project includes comprehensive unit tests across all platforms:
# Run all tests
dotnet test
# Run tests with coverage
dotnet test --collect:"XPlat Code Coverage"
# Run platform-specific tests
dotnet test --filter "Platform=Windows"
dotnet test --filter "Platform=macOS"
dotnet test --filter "Platform=Linux"
CI/CD pipeline runs tests on:
Contributions are welcome! Current focus areas:
Eclipse Public License 2.0 (EPL-2.0) - Same as Java SWT
Based on the Eclipse SWT project: https://www.eclipse.org/swt/