Michael Johnston
Michael Johnston

Reputation: 858

Give a button a pre set "Style" in Java Swing

Is there a way to set out what you want a button style to be then use this pre made style settings on all/certain buttons. For instance have a couple pre set button styles that you are able to set groups of buttons to have instead of having to change all the style settings for each button individually. Thanks for any help :)

Upvotes: 1

Views: 1120

Answers (1)

Dinh
Dinh

Reputation: 779

You can always create a custom button by extending JButton and use that one instead

public class CustomButton extends JButton {

    public CustomButtong(String text) {
        super(text);
        setOpaque(true);
        setBackground(Color.RED);
    }

}

Now you can import the class and use it just like a JButton, for example

CustomButton button = new CustomButton("Click me!");

You can modify the constructor to your needs.

Upvotes: 1

Related Questions