Search code examples
javaswinglook-and-feeljcomponentuimanager

What's a convenient way to set default settings for all JComponents


I want a way to set default settings like, background colour, size etc. for all components I use in my GUI, what's a convenient way to do this? so when I do new JButton or JLabel etc. it will already have the settings applied?


Solution

  • Write a factory method that returns your components with the defaults already applied, then retrieve them from the factory instead of directly creating them.

    Or write a method that accepts an instance of a JComponent and sets the desired defaults, that can be reused throughout your code.

    Or use a combination of both.

    Another option is to create and use your own "Look and Feel":

    ... but I would guess that this is much more involved than what you're looking for.