Custom JButton with different states, any ideas??

Hey, hope you guys can help.
What I want to do is to implement a custom JButton class with different states for the button. The button should have a "pressed" state, where the user has pressed it, and if the action triggered by this pressing gets approved, it should get selected. It will then get a different color and border.
I will have several buttons of this type in one panel, and they can all have different states at any time.
I do not want to use JToggleButton, as it is not the user that decides if it should be selected or not, but the logic "behind" (the dataflow).
So I want like a combination of JButton and JToggleButton...
How do I do this, any ideas, please?

I am not to sure if this is the idea you have in mind but...
This is something i have used before it is a tool bar. the button could be managed by another event it is an event listener at the moment.
As well as update only a specified button rather than all?
public class ToolBar extends JToolBar {
    public ToolBar(EventListener el) {
        this.setName("ToolBar");
        String[] imageFiles = { "Left.gif", "Relationgif", "Reload.gif", "TrafficRed.gif", "Home.gif", "Print.gif", "Help.gif" };
        String[] toolbarLabels = { "Entity", "Relationship", "Reload", "Stop", "Home", "Print", "Help" };
        Insets margins = new Insets(3, 3, 3, 3);
        for(int counter = 0; counter < toolbarLabels.length; counter++) {
            ToolBarButton button = new ToolBarButton(imageFiles[counter]);
            button.setToolTipText(toolbarLabels[counter]);
            button.setMargin(margins);
            button.setName(imageFiles[counter]);
            button.setVerticalTextPosition(BOTTOM);
            button.setHorizontalTextPosition(CENTER);
          //  button.setMnemonic(KeyStroke.VK_CAPS_LOCK);
            button.addActionListener(el);
            add(button);
    public void setTextLabels(boolean showLabels) {
        Component c;
        int i = 0;
        while((c = getComponentAtIndex(i++)) != null) {
            ToolBarButton button = (ToolBarButton)c;
            if (showLabels)
                button.setText(button.getToolTipText());
            else
                button.setText("");
//each button on the tool bar is an object of this class
public class ToolBarButton extends JButton {
    private static final Insets margins = new Insets(3, 3, 3, 3);
    //user selected to view tool bar as image only (default)
    public ToolBarButton(Icon icon) {
        super(icon);
        setMargin(margins);
    //user selected to view tool bar as text only
    public ToolBarButton(String iconName) {
        this(new ImageIcon(iconName));
    //user selected to view tool bar as image and text
    public ToolBarButton(String iconImage, String iconName) {
        this(new ImageIcon(iconImage));
        setText(iconName);
}

Similar Messages

Maybe you are looking for

  • How do I set up my second Ipod and itunes library (same computer)?

    I recently filled up my first Ipod, and want to load my second Ipod's software on the same computer without causing interference and problems with my first ipod and library. How do I load my second ipod's software and create a library just for it, wi

  • Servlet context in application.xml does not appear to work

    Hi all, I have created a very simple servlet and an index.html file with a link to it, then packaged it into a WAR file with the appropriate web.xml and ias-web.xml files. I then created an application.xml file referencing only this servlet and addin

  • Can't empty trash bin error: -8003

    I'm trying to delete files from my Mac. Whenever I try to empty my trash bin this message appears: Can't complete operation. Error found. (error: -8003) Please help!

  • Will a Serial Number for Photoshop CS5 Work for CS5 Extended?

    Hello, I've recently subscribed to Photoshop CS5 and Dreamweaver CS5.5. In my Order History, it says 'Photoshop CS5', not 'Photoshop CS5 Extended'. However the download links in my Order History does not work (yes, I do have Adobe Download Assistant-

  • Idsync resync error

    Hi, I installed ISW and all the required connectors. But when I use the idsync resync command , I always get invalid options error. Trying to sync from ds5.2 to AD idsync resync -D "cn=Directory Manager" -w password -o Sun -c The DN used above is the