How to change button color in java swing?



How to change button color in java swing?..

Answer / Amit Garg

To change the button color in Java Swing, you can set its background using BasicStroke. Here's an example:

```java
import javax.swing.*;
import java.awt.*;

public class ColorButton extends JButton {
public ColorButton(String text, Color color) {
super(text);
setBackground(color);
}
}
```
You can then use this custom button in your code.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Swing Interview Questions

What is the default look and feel of a Swing Component?

3 Answers  


What is the function of internal frame in swing?

1 Answers  


Is javafx better than swing?

1 Answers  


Which containers use a border Layout as their default layout in swing?

1 Answers  


Is swing still used?

1 Answers  


Which method of the Component class is used to set the position and size of a component?

1 Answers  


Explain the difference between jfc & wfc.

1 Answers  


What are the advantage of swing over awt?

1 Answers  


What is the function of abstractaction class?

1 Answers  


what do u mean by GUI framework

1 Answers  


When we should go for codebase in applet?

1 Answers  


What is swing and awt in java?

1 Answers  


Categories