So i have a GUI program called Safe25. Basically, if you press the buttons in the right order which is \"15032018\" the program closes itself. If you input a correct number, let
The answer is, no, not really - or at least not as you might expect.
The button's content is provided by the look and feel delegate, most of which ignore things like the background
property (or at least don't use it in ways you might think it should).
Instead, you need to remove these decorations and do a little of the work yourself
For example...
buttons = new JButton[10];
for (int i = 0; i < 10; i++) { // 10 Knöpfe im Array
buttons[i] = new JButton("" + i);
buttons[i].setFont(new Font("Courier", Font.BOLD, 34));
buttons[i].setContentAreaFilled(false);
buttons[i].setOpaque(true);
buttons[i].setBorder(new EtchedBorder(EtchedBorder.LOWERED));
buttons[i].setBackground(Color.RED);
buttons[i].addActionListener(this); //
}
This disables the area filling, replaces the border and makes the component transparent, which produces something along the lines of