Sunday, November 22, 2009

Colouring a Swing JButton - Java

This is extremely simple, but not intuitive. Without setting Opaque, and content area filled, the colour will not show; instead it will still display whatever is defined by the default look and feel. The below example will set the background of the button blue.


JButton button = new javax.swing.JButton();
button.setBackground(Color.BLUE);
button.setContentAreaFilled(false);
button.setOpaque(true);

0 comments: