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?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.