Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2004

Tip: Looking for answers? Try searching our database.

Change JToggleButton selected color

Thread view: 
Chris - 27 Feb 2004 02:01 GMT
I would like to change the color of a selected JToggleButton (in a
ButtonGroup) to red from grey. About the only solution I can find online
is to put this in my main program:

UIManager.put("ToggleButton.select", Color.red);

However this doesn't change anything for me. Strangely if I change my
JToggleButton class to JButton this line indeed does work:

UIManager.put("Button.select", Color.red);

By the way, all my buttons are actually from a derived class called
SymbolButton that extends JToggleButton. I'm running 1.4.2 on Linux.

Thanks,
Chris
Ike - 27 Feb 2004 03:16 GMT
Hi Chris,

Try this, it will get you started anyhow, from some code I have here....Ike

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.border.*;

public class JTASToggleButton extends JToggleButton {
   public boolean pressed;
   /** Creates a new instance of JTASToggleButton */
   public JTASToggleButton() {
       super();
       addMouseListener(new MouseAdapter(){
           //the following functions not needed since this is an adapter
class:
           public void mousePressed(MouseEvent Me){
               pressed=!pressed;
               if(pressed)
                   setForeground(Color.MAGENTA);
               else
                   setForeground(Color.BLACK);
           }
                   });
   }

}

> I would like to change the color of a selected JToggleButton (in a
> ButtonGroup) to red from grey. About the only solution I can find online
[quoted text clipped - 12 lines]
> Thanks,
> Chris
Chris - 01 Mar 2004 03:24 GMT
Thanks Ike. I tried adding a MouseListener to my JToggleButton class but
found that:
1. setForeground doesn't do anything, but setBackground does
2. setBackground changes the color of the non-selected buttons, not the
selected button

So I'm still looking for something to change just the color of the
selected button and nothing else.

Thanks,
Chris


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.