1

My code goes like this

class ActionPanel extends JPanel{
    private JButton calculate;
    private JLabel sup;
    private Border border;
    public ActionPanel(){
        calculate = new JButton("Calculate Bill");
        calculate.setOpaque(true);
        calculate.setBackground(Color.BLUE);
        sup = new JLabel("Total Cost", SwingConstants.CENTER);
        setLayout(new GridLayout(0,1));
        add(sup);
        add(calculate);
        }    
}

this goes to form part of a JFrame but when it is displayed after running the program the JButton won't change color unless I do setBorderPainted(false); but then the button looks weird because it has no border, what can I do so that the JButton changes color but I don't lose the Border

1 Answers1

0

Do you add the Action panel to the frame AFTER the frame is set visible?

If so, you must call repaint and (re)validate on the frame to make changes visible. Hope this helps, providing more code would help answering.

croraf
  • 4,332
  • 2
  • 31
  • 50