Setting JToggleButton's select color a real pain - any suggestions?

Hi,
I'm starting to get a bit frustrated trying to set the select color of a JToggleButton. I feel like I've wasted hours on something that should be a one liner, so I figured it's time to ask for help (again).
I'm trying to create a very simple panel of about five toggle buttons, in a ButtonGroup, with a grid layout (1 column, 5 rows). Basically I want to create a little navigation panel that resembles the left side of the preferences dialogs in Firefox / Thunderbird (if you've seen it). However, I'm having trouble setting the select color of the toggle buttons. I know it's possible to set the color using the UIManager / UIDefaults (I don't use orange, it's just an example)...
UIManager.put("ToggleButton.select", Color.ORANGE);... but I don't want to change the select color for every toggle button in my application.
I've also seen posts that recommend extending the ButtonUI of the look and feel that is being used. I don't think this is a good solution because I don't intend to extend the ButtonUI of every look and feel I want (or may want) to use.
Although I try to be picky about using quality code that is reusable, I'm at the point where I'm pretty much willing to use anything that will work, no matter how ugly. If you want to share in my frustration, try the following:
Create a tiny app with two JToggleButtons. Label one of them "Go" and the other "Stop". Add the Go and Stop buttons to a button group so that only one may be selected at a time. Make it so when the Go button is pushed it toggles on and is green. Make it so when the Stop button is pushed it toggles on and is red.
In fact, here's a quick hack of my tiny application. Just modify it to set the select color of stop to red and the select color of go to green.
import javax.swing.*;
import java.awt.*;
public class StopAndGo
     public StopAndGo()
          JFrame mainFrame = new JFrame("Stop And Go");
          JPanel contentPanel = new JPanel(new FlowLayout());
          JToggleButton stopButton = new JToggleButton("Stop");
          JToggleButton goButton = new JToggleButton("Go");
          ButtonGroup group = new ButtonGroup();
          group.add(stopButton);
          group.add(goButton);
          contentPanel.add(stopButton);
          contentPanel.add(goButton);
          mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          mainFrame.add(contentPanel);
          mainFrame.pack();
          mainFrame.setVisible(true);
     public static void main(String[] args)
          SwingUtilities.invokeLater(new Runnable()
               public void run()
                    new StopAndGo();
}As far as I'm concerned setting the select colors shouldn't be more than two 'setSelectColor(Color.SOMETHING)' lines. After all, one of the first things anyone will tell you about a toggle button is that it changes colors when it's pushed on.
BTW, I'm using Java 1.5 on Linux.
Thanks in advance for any help,
Ryan

This is a problem with the way the look and feels work and the simplest solution is to bypass it altogether.
The code below takes each button and uses some GIFs to define what the icons are for the buttons. One is for the normal Icon for the button and the other is for when the button is selected.
You can create your own GIFs with the colours you want. So a Red Stop button selected icon and a green go button selected icon. Two not selected icons are need to show the button when it is not pressed.
Using the border just stops the normal button being drawn. Just the icon is seen.
import javax.swing.*;
import java.awt.*;
public class StopAndGo
     public StopAndGo()
          JToggleButton stopButton = new JToggleButton("");
          JToggleButton goButton = new JToggleButton("");
          JFrame mainFrame = new JFrame("Stop And Go");
          JPanel contentPanel = new JPanel(new FlowLayout());
          ButtonGroup group = new ButtonGroup();
    stopButton.setSelectedIcon(new ImageIcon("whiteCross.gif"));
    stopButton.setIcon(new ImageIcon("blackCross.gif"));
    stopButton.setBorder(BorderFactory.createEtchedBorder());
     goButton.setSelectedIcon(new ImageIcon("whiteCircle.gif"));
    goButton.setIcon(new ImageIcon("blackCircle.gif"));
    goButton.setBorder(BorderFactory.createEtchedBorder());
          group.add(stopButton);
          group.add(goButton);
          contentPanel.add(stopButton);
          contentPanel.add(goButton);
          mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          mainFrame.add(contentPanel);
          mainFrame.pack();
          mainFrame.setVisible(true);
     public static void main(String[] args)
          SwingUtilities.invokeLater(new Runnable()
               public void run()
                    new StopAndGo();
}

Similar Messages

  • I am using ethernet and am using a Linksys SE1500 5- port fast etherner switch, i cant seem to sign in on the apple for anything although I have accounts set up in itunes/apple and netflix . Any suggestions PLEASE have spent 3 hours argh. thanks

    I am using ethernet and am using a Linksys SE1500 5- port fast etherner switch, i cant seem to sign in on the apple for anything although I have accounts set up in itunes/apple and netflix . Any suggestions PLEASE have spent 3 hours trying everything I can think of. Any help will be appreciated!
    I have a linksys router but it isn't strong enough to get to this computer, so we are using ethernet.
    Thank you
    Colleen

    Welcome to the Apple Community.
    Are you getting any messages about date and time.
    Have you tried restarting the Apple TV by removing ALL the cables for 30 seconds.
    Are you connected to the network correctly.

  • When printing to the dye sublimation epson stylus pro 7700 using adobe illustrator it is required that I mirror the image.  When mirroring the image the print colors are muted.  Not mirrored and the print colors are perfect.  Any suggestions?

    When printing to the dye sublimation epson stylus pro 7700 using adobe illustrator it is required that I mirror the image.  When mirroring the image the print colors are muted.  Not mirrored and the print colors are perfect.  Any suggestions?

    CS5
    On Tue, Oct 7, 2014 at 9:49 AM, ADBEDesigner <[email protected]>

  • HT1386 I'm trying to purchase music from itunes on a different laptop than I originally set-up my ipod and itunes account. Any suggestions?

    I'm trying to purchase music from itunes on a different laptop than I originally set-up my ipod and itunes account. Any suggestions?

    To load music on the iPod from other that the syncing computer follow the instructions here:
    Using iPhone, iPad, or iPod with multiple computers

  • The paint bucket tool is not working properly. The colors does not change, any suggestion?

    The paint bucket tool is not working properly. The colors does not change, any suggestion?

    Maybe on the wrong layer.
    It would be more beneficial if you capture your screen with the layers panel open and any layers that are collapsed, expand them.

  • Trying to add a signature on my apple email but the preferences will not let me select a signature...any suggestions

    Trying to add a signature on my apple email but the preferences will not let me select a signature...any suggestions

    copping out wrote:
    Trying to add a signature on my apple email but the preferences will not let me select a signature...any suggestions
    Lion or Snow Leopard?
    Either way go to Mail>Preferences>Signatures
    And make one.

  • My 2nd gen iPad woke up today and decided to load all 800  apps, I've reset,restored and still the minute I connect wifi it's off to the races. It is set to manually manage apps. Are there any suggestions?

    My 2nd generation iPad woke this morning and decided to load all of my apps 800+ and I don't seem able tp prevent it. It is set to manually manage apps and I have reset, restored and the minute I reconnect with wifi it starts loading. Any suggestions out there on how to correct this?

    @chris_l -- yeah I was worried that might be the case, still I'm not sure if that explains why it keeps failing the burn process part way through?
    I've tried this and that in Linux but without much luck. I'm still quite a noob with a lot of Linux things and this is the first time I'm trying anything to do with optical disks/drives etc. so I'm learning as I go...
    The disk that failed in Windows but was 'readable' in Linux did just pass a run through ddrescue -- i.e. it created an output file okay and did not report any errors in the process.
    However when I mounted the resulting image and tried to copy the files across the first folder reported an "input/ouput error" (just using gui copy+paste in Thunar file manager)
    ...the other folders did copy okay though!
    It seems as though it's the lead-in / lead-out and disc finalizing process that are the main fail points with the burn operation. I don't know if InfraRecorder is any good or likely to be the problem? Anyway the drive cam with Nero (inc. Linux version) so might give either or both of these a go too, if they don't work either then at least I wont be short of something to rest a mug o' tea on
    @ chris_l (again) -- the Plextor drives do have a "Vari-Rec" feature which allows a user to 'tweak' the laser power / output level so I might try this too.
    @alphaniner -- thanks I've not seen this package before, I'm guessing it's a bit like cdparanoia but for dvds?!
    Thanks for the help!
    (pre-post) UPDATE >>> I've just mounted my Windows partition  in Linux so I'll have a crack at burning the files using cdrtools before I resort to throwing the dvd drive out of the window and chasing it around the yard with a lump hammer

  • My ipod nano will turn on and play but the viewing screen goes out and I cannot access the information to select different playing options. Any suggestions?

    My ipod nano will turn on and play but the viewing screen will not come on and I cannot access the information to select different playing options. It glows white background light then goes dark for the entire time I am using it. Any suggestions?

    I had the same problem.  Someone here told me to make sure my earbuds were in securely.  Push until they click in place.  It solved the problem.  The music still plays even though the screen goes to sleep.  Hope this helps.

  • When syncing, i often do not get the current selections added or past selections deleted fom the ipod. any suggestions?

    when i sync up my ipod, i select new songs to add and remove. although itunes on the computer says syncing, the songs are not put on or taken off. any help to fix this would be most appreciated.

    get an iPhone? 
    as to date - that is an EXIF entry placed there by the camera (phone) and iPhoto just reads it so the cause is the phone recording it incorrectly somehow - you can export one to the desktop and look at the EXIF data using simple EXIF viewer - http://homepage.mac.com/aozer/EV/
    As ro faces, iPhoto does not distinguish by camera - it processes photos - if the photos taken by one camera are acting differently from the photos taken by other cameras then again I would look to the camera - contact their support
    LN

  • I have a tungsten t2 that has stopped the audio alert alarm function and just flashes a light when the alarm activates. I made sure it is the Alarm Sound is set at high but still not working. Any suggestion? Thanks

    Post relates to: Tungsten T2

    First try a soft reset by pressing the Reset button on the back of the unit.
    Are you using any third-party calendars such as DateBk or Agendus?
    smkranz
    I am a volunteer, and not an HP employee.
    Palm OS ∙ webOS ∙ Android

  • Third-party widget not displaying properly (c/p code set to 700px width, shows up as narrow mobile width)... any suggestions?

    My client is wanting to update the Store page on his website to an integrated BandPage widget. He set the width to 700px on their site, but when I copy/pasted the code into Muse & publish, it only displays as a narrow mobile version (hidden sample link: http://www.griffinanthony.com/storewidget). We contacted BandPage to make sure everything's set correctly on their end; they've assured us it is. We can't figure out why it's not working in Muse -- should be as simple as the many other widgets we placed throughout his site?!
    Here's the code BandPage generated: <script async src="//www.bandpage.com/extensionsdk"></script><div class="bp-extension" data-bandpage-bid="453666329342337024"></div>
    ..set to a grid layout (attach'd).
    Any suggestions would be appreciated. Thx!

    FYI - I figured out a way around this by dragging out the border handles of the placed code; it automatically jumped to the width it was meant to be (attach'd). Hope this tip helps others in case they're faced with a similar dilemma.

  • How can I change the 'selected' color of one JToggleButton only.

    Hi,
    This seems like a simple / trivial question, but I just can't figure it out. Is there a way that I can create a JToggleButton and change the selected color of only that JToggleButton.
    I'm trying to create a simple sidebar like component for navigation within my app. A group of JToggleButton[s] added to a ButtonGroup (with the proper layout / sizing) works great, but the default JToggleButton colors don't suit my needs. I know that I can change the colors using the UIManager / UIDefaults, but I don't want to change the defaults for every JToggleButton in my app. I only want to change the defaults for a few select JToggleButton[s].
    For example, I can do this:
    UIManager.put("ToggleButton.select", UIManager.getColor("Table.selectionBackground"));
    UIManager.put("ToggleButton.background", UIManager.getColor("Table.background"));but I'd rather do something like this:
    JToggleButton jtb = new JToggleButton("Toggle Button Text");
    jtb.setSelectedColor(UIManager.getColor("Table.selectionBackground"));
    jtb.setBackground(UIManager.getColor("Table.background"));The only thing is, I can't find any method that is the equivilant of 'setSelectedColor(Color)' for JToggleButton.
    I know I could do it by adding some listeners to the JToggleButton[s], but that seems a little complicated for something like changing a color.
    I'd also seen a solution in the forums where someone had extended the ButtonUI of the pluggable look and feel they were using. I'm not interested in modifying the look and feel I'm using. As far as I'm concerned, that would defeat the purpose of having a pluggable look and feel as I would have to duplicate my efforts for every look and feel I want to use.
    Any help would be appreciated,
    Ryan

    try this
    import javax.swing.*;
    import java.awt.*;
    class Testing extends JFrame
      public Testing()
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(250,75);
        setLocation(400,300);
        JPanel jp = new JPanel();
        JToggleButton jtb = new JToggleButton("Toggle me");
        jtb.setUI(new MyUI());
        jp.add(jtb);
        getContentPane().add(jp);
      public static void main(String args[]){new Testing().setVisible(true);}
    class MyUI extends javax.swing.plaf.metal.MetalToggleButtonUI
      public Color getSelectColor(){return Color.BLACK;}
    }

  • I have Photoshop CS5 and a Epson 3880 . The print setting dialogue box won't open when selecting color output PRINTER MANAGES COLORS

    I have Photoshop CS5 and a Epson 3880 . The print setting dialogue box won't open when selecting color output PRINTER MANAGES COLORS
    It does ope when selecting PHOTOSHOP MANAGES COLOURS . This is first time in 7 year this has happened.
    Any one with ideas/

    What is your screen resolution?
    What operating system?

  • Set Selection Color

    I'm still trying to understand the InDesign SDK. I'm working on a plug-in and I want to set the current selection, whatever object it might be, to have an RGB or Lab fill or stroke color. I figured out how to get the current selection but I don't know how to figure out what I can do to it.<br /><br />I get the current selection with:<br />     Utils<ISelectionUtils> iSelectionUtils;<br />     ISelectionManager* selectionMgr = iSelectionUtils->GetActiveSelection();<br /><br />So how do I make an RGB or Lab color and tell the selection to set it's fill/stroke color to it ? I would prefer not to have to create a swatch for it first.<br /><br />Thanks,<br />Matt

    Snippet didn't work. Here is a normal .png
    Message Edited by for(imstuck) on 06-11-2010 01:54 PM
    CLA, LabVIEW Versions 2010-2013
    Attachments:
    ugh.PNG ‏21 KB

  • Using Mac 0S X Yosemite, in Print Setting when I select layout / arrows select print settings / there is no Basic drop down box to set color management on or off. I'm using Artisan 835 printer.

    Using Mac 0S X Yosemite, in Print Setting when I select layout / arrows select print settings / there is no Basic drop down box to set color management on or off. I'm using Artisan 835 printer.

    No - I got the iMac 27 because it was calibrated at the factory(?) and was highly recommended by friends and photographers. No complaints  at all, but this printer issue is driving me crazy. I was thinking that if I upgraded to an epson pro printer ICC profile will be on there website. I can't find any for the 835. By the way I didn't calibrate the old dell monitor either and I have had several photos published with no problem at all. Just a note, on epson website there are no printer stating they will run with 10.10 Yosemite. I was looking at the R2000 series. Right now I editing photos that I have to have ready by Jan, maybe by then epson will have something ready.

Maybe you are looking for

  • Consuming Web Services using UTL_DBWS

    Hi, I am trying to call a web service using UTL_DBWS package. But I am getting this error: ORA-29532: Java call terminated by uncaught Java exception: [failed to localize] No Deserializer found! It is failing at this point: l_result := sys.UTL_DBWS.i

  • I redeem my accound $15 via Gift Card,shows on my ID BUT when I purchase request for my pastword and shows its not there,what's going on?

    I just purchase a gift card for my iTunes account. Follow the instruction and place the code to redeem my account. On iTUnes Store Home it shows $15.00 has been credited to my account but when I got to purchase its not there and request for my credit

  • How To Work Smarter With Preset Adjustment Layers ?

    Photoshop CS5 (maybe CS6 too ?) From the 'Adjustments' panel I often use a preset Adjustment Layer (I've saved some of my own in here). I click on the preset adjustment layer I want and it appears in the Layers panel with a generic name 'Curves [X']

  • Booting safe mode hangs during fsck_hfs rMBP + 10.8.0

    When trying to boot in safe mode (holding down shift while power on) to troubleshoot issues with the upgrade to 10.8.1 the boot process hangs indefinitely. When switching on verbose and safe mode (nvram boot-args="-x -v") I see that it proceeds until

  • Query using NTILE function

    Is there any better way to write this query: SELECT      MIN(EMPNO) "StartEmpno",      MAX(EMPNO) "EndEmpno",      partition      FROM      SELECT                EMPNO,                NTILE(20) OVER (ORDER BY EMPNO ASC ) as partition           FROM