File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JToggleButton background color Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JToggleButton background color" Watch "JToggleButton background color" New topic

JToggleButton background color

kevin bennett

Joined: Aug 22, 2001
Posts: 15
I'm trying to use a ButtonGroup of JToggleButtons and a CardLayout to simulate the function of a JTabbedPane with a different look & feel. To do that I need to have the selected JToggleButton be the same color as the selected panel in the CardLayout. My problem is this - no matter what I do I can't get the selected JToggleButton to match the panel. I've tried setting the background color in the button to the exact color of the panel and then verifying that the colors are the same RGB color (in this case 204,204,204) but even then the button is darker than the surrounding area. What gives? I've also tried setOpaque(false) to no avail. Any help is appreciated. Thx.
Another solution to this problem would be changing the appearance of the tabs in a JTabbed Pane (I'm assuming in the TabbedPaneUI), but I don't know how to do that. If someone has an answer to this I would LOVE to hear it.
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
if you set the JButton to setOpaque(true) it *should* have the same backgound as its parent where its placed.
From little experience trying to change the appearance of buttons I think they have some additional color layer. But you could check that simply by reading through the original source. Same for JTabbedPane and its UI class. this should shed some ligth on your question.
another solution could be to just use JLabel, Border, and MouseListener (in fact I'd say JButtons aren't anything else?!).
I agree. Here's the link:
subject: JToggleButton background color
It's not a secret anymore!