Using CSS over Java code gives you the following benefits:
- Dividing responsibilities: You use Java code to write logic and leave all styling to a style sheet.
- Avoiding duplicated code: If you want all your buttons to look slightly different, you can just write one line in the CSS instead of adding an API call to each button.
- Simplifying changes: If you have changed your mind about that button, you again need to make changes in one place. Of course, this is achievable by Java means as well, but in CSS it's way more convenient.
- Changing styles: You can have several CSSes that can be substituted by just one method call. Skins, day/night modes, accessibility support—all these tasks can be addressed by switching style sheets.