Creation of a Custom Look-and-Feel

Everything we’ve covered in this chapter up to this point has been useful background information for the ultimate application customization strategy: creating your own L&F. As you might guess, this is not something you’ll do in an afternoon, nor is it usually something you should consider doing at all. However, thanks to the L&F framework, it’s not as difficult as you might think. In a few instances, it actually makes sense, such as when you’re developing a game. You’ll likely find that the most difficult part is coming up with a graphical design for each component.

There are basically three different strategies for creating a new L&F:

  • Start from scratch by extending LookAndFeel and extending each of the UI delegates defined in javax.swing.plaf.

  • Extend the BasicLookAndFeel and each of the abstract UI delegates defined in javax.swing.plaf.basic.

  • Extend an existing L&F, like MetalLookAndFeel, and change only selected components.

The first option gives you complete control over how everything works. It also requires a lot of effort. Unless you are implementing an L&F that is fundamentally different from the traditional desktop L&Fs, or you have some strong desire to implement your own L&F framework from scratch, we strongly recommend that you do not use this approach.

The next option is the most logical if you want to create a completely new L&F. This is the approach we’ll focus on in this section. The BasicLookAndFeel has been designed as an abstract framework ...

Get Java Swing, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.