How do I? Can I?
public class Jbutton {
public static void main (String[] args){
JButton button = new JButton("I'm colorful!");
button.
What do I do here ^ to set the button color?
}
}
How do I? Can I?
public class Jbutton {
public static void main (String[] args){
JButton button = new JButton("I'm colorful!");
button.
What do I do here ^ to set the button color?
}
}
You have 2 options either use setBackground
or setIcon
E.g.
button.setBackground(myColor);
button.setIcon(new javax.swing.ImageIcon(pathToIcon));
Using your example:
public class Jbutton {
public static void main (String[] args){
//You're going to need some context for this like a JFrame
JButton button = new JButton("I'm colorful!");
button.setBackground(Color.RED);
}
}
Though I think for a more enlightening section of code, you might explore This Question to see how some parts of swing and AWT work.
I believe its like so
{
JButton btn = new
JButton(String.valueOf(i));
btn.setBackground(Color.BLACK);
btn.setForeground(Color.GRAY);
p3.add(btn);
}
Using my phone so trouble editing it to post code, that's what I used on a previous project though if that helps