How to Refresh Old Swing UIs with a Clean, Modern Aesthetic
Java Swing has been powering desktop applications for over two decades. While Swing is incredibly capable and stable, its default look and feel has aged—often making apps look like relics of the early 2000s.
FlatLaf is a modern, open-source look and feel that breathes new life into Swing UIs, offering:
✅ A flat, clean design inspired by IntelliJ IDEA and modern UI trends
✅ Dark and light themes out of the box
✅ High-DPI scaling support
✅ Easy customization
In this article, you’ll learn how to:
- Install FlatLaf in a Swing project
- Switch between themes
- Tweak the appearance with properties and custom colors
- Build a professional-looking desktop app in minutes
Let’s get started!
Why Use FlatLaf?
FlatLaf stands out among Swing look and feels because:
- It supports Windows, macOS, and Linux consistently
- It’s actively maintained
- It’s designed to look modern without heavy custom drawing code
- It integrates with popular Swing frameworks and components
If you’ve been stuck with Metal, Nimbus, or legacy third-party themes, FlatLaf can dramatically improve your app’s visual appeal.
1️⃣ Setting Up FlatLaf
FlatLaf is published to Maven Central, making it simple to integrate.
Maven Dependency:
| 1 2 3 4 5 |
|
Gradle:
| 1 |
|
2️⃣ Applying FlatLaf in Your Application
You can install FlatLaf globally in your main method before creating any Swing components.
Example:
| 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
Launch this example, and you’ll immediately see the flat, modern styling applied.
ADVERTISEMENT
3️⃣ Switching Between Themes
FlatLaf offers four built-in themes:
FlatLightLafFlatDarkLafFlatIntelliJLafFlatDarculaLaf
To use a dark theme:
| 1 |
|
Or load IntelliJ’s classic light theme:
| 1 |
|
4️⃣ High-DPI Support
FlatLaf automatically scales components on HiDPI screens, so text and icons look crisp on Retina and 4K displays. You don’t need extra configuration—just ensure your Java runtime is up to date (Java 11+ recommended).
5️⃣ Customizing the Look and Feel
FlatLaf provides several ways to tweak styles:
Setting UI Defaults
For example, change button arc radius or focus width:
| 1 2 |
|
Loading Custom Themes
FlatLaf supports .properties theme files to override colors, fonts, and styles.
Example:
| 1 2 3 4 5 |
|
In resources/themes/myTheme.properties, you can override specific keys:
| 1 2 |
|
6️⃣ FlatLaf Extras
FlatLaf Extras is an optional library providing:
- Animated transitions
- Accent color support
- Custom font configurations
Maven:
| 1 2 3 4 5 |
|
Example: Installing a custom accent color
| 1 |
|
7️⃣ Demo Application
Here’s a minimal example combining several features:
| 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
Run this code and see a sleek, dark-themed UI.
8️⃣ Tips for Best Results
✅ Set the look and feel before creating any Swing components
✅ Use consistent font sizes across your app
✅ Test on different platforms (Windows, macOS, Linux)
✅ Combine FlatLaf with modern icons (e.g., Material Icons)
✅ Avoid mixing FlatLaf with unsupported third-party look and feels
Conclusion
With FlatLaf, you don’t have to abandon Swing to achieve a modern look and feel. You can refresh your applications quickly and provide a clean, professional user experience that feels up to date.
Explore the official project for even more customization options and examples.
Resources
- FlatLaf GitHub Repository
- FlatLaf Themes
- FlatLaf Documentation
1万+

被折叠的 条评论
为什么被折叠?



