Altering the button appearance in ECS100 library

Fri, Aug 11, 2023 One-minute read

Modifying the UI Button with an Icon

In the ECS100 library, there is not too much you can do to change the appearance of things but they’ve kindly allowed you to alter the button appearance as UI.addButton() actually returns the button as well as putting it on the screen.

You just need to capture it in a variable and then make changes to after that.

Jbutton myButton = UI.addButton("My Button", this::handleNewBtn);

You can customize the appearance of the button by setting properties such as the background color, foreground color, and font. For example:

myButton.setBackground(Color.RED);
myButton.setForeground(Color.WHITE);
myButton.setFont(new Font("Arial", Font.BOLD, 14));