So it seems like theres a bug on my end, because the exact same code works for a friend, but does not for me. Note: I use mac os and the newest version of eclipse.
But whats my problem? Trying to use setBackground(Color.something) for JButtons does not work as it should. When starting the program below, the buttons background should be red like this:
For me, it just looks like this
So nothing really happens, setForeground works as expected. Using setBackground on Frame or TextField also works as expected. It just does not work on Buttons, JButtons for me. Someone knows any reason for that?
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
public class Test extends JFrame {
JButton[] button = new JButton[10];
public Test() {
setLayout(new FlowLayout());
for(int i = 0; i < 10; i++) {
button[i] = new JButton("" + i);
add(button[i]);
}
for (int i = 0; i < 10; i++) {
button[i].setBackground(Color.green);
}
setSize(250,200);
setVisible(true);
}
public static void main(String[] args) {
Test test = new Test();
}
}