Basic, basic question re: button coloring (change from default blue)

Hi folks!

I wish to create a button which has a black background, and which - when pressed - still remains black. The code I have so far follows.

theButton =new JButton();

theButton.setBackground(Color.black);

theButton.setLocation(new Point(38, 13));

theButton.setSize(new Dimension(30, 35));

theButton.setRolloverEnabled(false);

theButton.setForeground(Color.black);

theButton.setBorderPainted(false);

theButton.setFocusPainted(false);

theButton.setToolTipText("Move Up");

theButton.setIcon(new ImageIcon(getClass().getResource("/iamabutton.gif")));

When this executes, the button does indeed have a black background (to make my .gif icon blend well ;) but when the user clicks the button, its background turns to the default light blue.

I've tried using my IDE's autocomplete feature to see what method call I can use to stop this - nothing. Java's documentation reveals nothing useful. Even a search of this site using the textfield at the top right of the screen hasn't found anything to help me.... it's pretty obvious from this that it's a really dumb question to be asking...

But, can anyone help me get rid of that blue on user-click, please? Perhaps an indication of what methods I should use to set my button's visual attributes, a tutorial... anything :)

[1646 byte] By [kay_jay_1949a] at [2007-11-26 16:41:07]
# 1
Try this:theButton.setUI(new BasicButtonUI());
Rodney_McKaya at 2007-7-8 23:08:06 > top of Java-index,Desktop,Core GUI APIs...
# 2
OrUIManager.getDefaults().put( "Button.select", Color.BLACK );though this will affect all buttons.
JayDSa at 2007-7-8 23:08:06 > top of Java-index,Desktop,Core GUI APIs...
# 3

> Or

> UIManager.getDefaults().put( "Button.select", Color.BLACK );

> though this will affect all buttons.

The UI is getting this color from the UIManager every time it's painting the button press, so you can't use it if you have another type of button.

Looking at the code it looks like the person that wrote this wanted to do it only once but forgot to implement it all the way...

Rodney_McKaya at 2007-7-8 23:08:06 > top of Java-index,Desktop,Core GUI APIs...
# 4

"it looks like the person that wrote this wanted to do it only once but forgot to implement it all the way"

Lol, or doesn't know what she's doing :)

Cheers for the pointers - off to have a play around with it now (at a brief glance and readup on component UIs it seems like exactly the sort of thing I need!)

Thanks :)

kay_jay_1949a at 2007-7-8 23:08:06 > top of Java-index,Desktop,Core GUI APIs...
# 5
> I wish to create a button which has a black background, and which - when pressed - still remains blackbutton.setContentAreaFilled( false );
camickra at 2007-7-8 23:08:06 > top of Java-index,Desktop,Core GUI APIs...