CheckBox icon

Hello

the following code shows a JCheckBox that changes its background color when selected, thus serving as an eye-catcher in a setting with several columns of check boxes.
The only thing I would improve is that the ceckbox should keep the normal ocean LAF when they are disabled. Even when I comment out the special colouring and just do a super.paintIcon (...), it remains flat gray. No idea why?
import java.awt.*;  
import java.awt.event.*;  
import javax.swing.*;

public class HighlightedCheckBox extends JFrame {
  JCheckBox cbx;

  public HighlightedCheckBox() {
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    setSize(300,200);
    setLayout(new FlowLayout(FlowLayout.LEFT, 40, 40));
    cbx= new JCheckBox("The modified checkbox");
    HighlightOnSelectIcon icon= new HighlightOnSelectIcon(cbx);
    cbx.setIcon(icon);
    JCheckBox cb= new JCheckBox("Above checkbox enabled", true);
    cb.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
     cbx.setEnabled(!cbx.isEnabled());
      }
    });
    add(cbx);
    add(cb, BorderLayout.SOUTH);
    setVisible(true);
  }


  public static void main(String args[]) {
    EventQueue.invokeLater(new Runnable() {
      public void run() {
     new HighlightedCheckBox();
      }
    });
  }


  class HighlightOnSelectIcon extends javax.swing.plaf.metal.MetalCheckBoxIcon {
    JCheckBox cb;

    public HighlightOnSelectIcon(JCheckBox cb) {
      this.cb= cb;
    }

    protected void drawCheck(Component c, Graphics g, int x, int y) {
      g.setColor(Color.BLACK);
      super.drawCheck(c,g,x,y);
    }

    public void paintIcon(Component c, Graphics g, int x, int y) {
//      if (cb.isSelected()) g.setColor(Color.GREEN);
//      g.fillRect(x,y,getIconWidth()-3,getIconHeight()-1);
      super.paintIcon(c,g,x,y);
    }
  }

}

Extend the wrong class. javax.swing.plaf.metal.MetalCheckBoxIcon is a vestige of days before the ocean; the box used by ocean icon is javax.swing.plaf.metal.MetalIconFactory.CheckBoxIcon - you can't expand, as is a private static class.

If appearance is important to you, you could encapsulate an icon from the UIManager. Maybe something like

  class HighlightOnSelectIcon extends javax.swing.plaf.metal.MetalCheckBoxIcon {

    private Icon wrappedIcon = UIManager.getIcon("CheckBox.icon");

    @Override
    protected void drawCheck(Component c, Graphics g, int x, int y) {
      g.setColor(Color.BLACK);
      super.drawCheck(c, g, x, y);
    }

    @Override
    public void paintIcon(Component c, Graphics g, int x, int y) {
      wrappedIcon.paintIcon(c, g, x, y);
      JCheckBox cb = (JCheckBox) c;
      if (cb.isSelected()) {
        g.setColor(Color.GREEN);
        g.fillRect(x, y, getIconWidth() - 3, getIconHeight() - 1);
        drawCheck(c, g, x, y);
      }
    }
  }

Oh, and the icon is designed as a shared resource. This is why paintIcon is passed to the component to which the icon should be painted. There is no need to maintain a reference to the JCheckBox as an instance field.

DB

Tags: Java

Similar Questions

  • Can someone explain please the icon with a check mark phone in iTunes.

    I would just like someone to explain to me how the iphone with the checkbox icon in iTunes on my phone

    See you in iTunes (on the Mac screen)?  Can you explain more in detail when you see it?  There is little 'touch' on the horizontal bar in the iTunes window, but this probably isn't what you describe because there is no "tick" here.

  • Icon for Network Magic Folders REMOVAL!

    Hello.  I installed my Linksys WRT54G2 router software, and auto-installé Network Magic (Trial Version).  During installation, 2 icons appeared on my desk.  "Network Magic Folders" and "Network Magic", the latter is a shortcut.  I tried to remove the "Network Magic Folders" icon and it is mounted permanently on the desktop.  I read a post with a similar prob, but the "fix" was to right click on the NM icon on the taskbar, click on 'options', under general, select the checkbox 'icons hide NM.

    Of 'options' menu when right clicking the icon on the taskbar NM or the notification icon, there is not.  How can I remove this icon, without uninstalling NM?

    Thank you

    Nawlins games

    OK open magic network > go to tools at the top > options > uncheck "show shared folders on the desktop icon.

    simple as that.

  • CheckBox and icons in the tree?

    APEX 4.2.5

    ADR 2.0.6

    Topic: Application of productivity - 226 *.

    I'm currently implemented of Alex Nuijten to change one part of the tree to include check boxes, but ran into a couple of problems.

    URL: http://nuijten.blogspot.com/2013/07/apex-tree-with-checkboxes.html

    First problem I came across: the 'value' column must be a number

    Second: 'icon' must be null.  (otherwise, it will infringe on the boxes)

    Has anyone else encountered this type of problems?

    Has anyone solved? If so, how?

    Thank you very much

    MK

    Hi Mike,.

    check my https://github.com/tompetrus/oracle-apex-ajax-tree github and my sample app https://apex.oracle.com/pls/apex/f?p=69001:3 - I actually just added the ability to define additional plugins, so you can run the tree with check box selected. Do not - that - hard to understand, and all the source files are available on github. (and the related blog is mine)

  • Icon Checkbox

    What does the box in the upper left corner of the icons?

    Hello djrwell,

    The box does nothing in particular, but it's another way to distinguish which files are selected at any particular time. According to a configuration of users, this may help because of color issues.

    Hope this helps

    Chris.H
    Microsoft Answers Support Engineer
    Visit our Microsoft answers feedback Forum and let us know what you think.

  • I can't display icons in the header of the yahoo mail, how to fix?

    The yahoo icons do not work with Mozilla Firefox for the desktop browser, are there patches?
    Thank you
    Michelle

    Usually, this is caused by the font substitution of website with a standard set of fonts. You can check and undo this change on the Options page:

    "3-bar" menu button (or tools) > Options > content

    Click on the "Advanced" button and if the checkbox "Allow pages to choose their own fonts, instead of my selections above" is empty, go ahead and check it out. So OK this change.

    If you recharge Yahoo mail, display the icons?

  • In the forum Coursera pages there are different icons and buttons, but I see that only holders of palce, small squares with letters in there. Any help?

    In the pages of the coursera.org forum, there are different icons and buttons. They do not display correctly. I can see only tiny forms square with characters in them. Hovering on them can display information in some cases, but it is not very convenient. Although they recommend Firefox, I use Chrome instead. Chrome has no questions here so far. Is it possible to view these icons correctly?

    Many sites now use downloadable fonts to create their icons instead of the traditional image files. So, there are some Firefox settings that might be a factor, as well as the NoScript extension, if you use this (blocked objects).

    (1) in the dialog box fonts Advanced, unchecking the checkbox which allows the site to use its own choice of fonts. To check that:

    "3-bar" menu button (or tools) > Options > content > button "Advanced".

    Here you must "allow pages to choose their own fonts.

    (2) on the deactivation of fonts downloaded in: config. It's less likely, or you remember probably not, but here's how to check on it.

    • In a new tab, type or paste Subject: config in the address bar and press ENTER. Click on the button promising to be careful.
    • In the search box at the top of the list, type or paste the gfx and make a pause so that the list is filtered
    • If gfx.downloadable_fonts.enabled preference is bold and user, set false, double-click it to return it true.

    This seems useful.

  • Icons, twitter bolts on the site are not displayed?

    According to the bounding, icons pictures, twitter bolts on the site are not displayed?
    Help please?

    Many sites now use downloadable fonts to create their icons instead of the traditional image files. So, there are some Firefox settings that might be a factor, as well as the NoScript extension, if you use this (blocked objects).

    (1) in the dialog box fonts Advanced, unchecking the checkbox which allows the site to use its own choice of fonts. To check that:

    "3-bar" menu button (or tools) > Options > content > button "Advanced".

    Here you must "allow pages to choose their own fonts.

    (2) on the deactivation of fonts downloaded in: config. It's less likely, or you remember probably not, but here's how to check on it.

    • In a new tab, type or paste Subject: config in the address bar and press ENTER. Click on the button promising to be careful.
    • In the search box at the top of the list, type or paste the gfx and make a pause so that the list is filtered
    • If gfx.downloadable_fonts.enabled preference is bold and user, set false, double-click it to return it true.

    This seems useful.

  • My icons 'Blackout' when I click or put my pointer over them. How can I stop this?

    I had this problem for years, but it doesn't me don't bother you as much as before, I used a dark theme. I recently changed to a lighter and this is now more visible. When I have my point or a button on the favorite icon, the "bottom" so that the icon becomes black, either completely, or partially.

    I tried to restart Firefox, reinstall the theme and the Firefox but the problem persists.

    Any ideas would be welcome, if necessary uninstall is a solution for losing Favorites etc would also be useful. If this problem is already on here please show me. I couldn't find a solution.

    Thank you.

    Hello J.Sharkey, try disabling graphics hardware acceleration. As this feature has been added to Firefox, it has gradually improved, but there are still some problems.

    You will have to perhaps restart Firefox for it to take effect, so save any work first (e.g. you compose mail, documents online that you are editing, etc.).

    Then perform the following steps:

    • Click on the orange top left Firefox button, then select the 'Options' button, or, if there is no Firefox button at the top, go to tools > Options.
    • In the Firefox options window, click the Advanced tab, and then select 'General '.
    • You will find in the list of parameters, the checkbox use hardware acceleration when available . Clear this check box.
    • Now restart Firefox and see if the problems persist.

    In addition, please check the updates for your graphics driver by following the steps in the following knowledge base articles:

    This solve your problems? Please report to us!

    Thank you.

  • Firefox not displaying only not the icons on web page correctly except in safe mode

    Hello. We develop a website for the moment and I don't have FF in safe mode some of the icons are not displayed correctly. All other browsers work fine and it will display in FF without any problem. The site is www.livingonmars.com and the icons are the 2 arrows in the upper right of the slideshow. When in safe mode, I see two arrows. Boot in normal mode I see the bottom half of the arrow to the left and half the right arrow above.

    In safe mode, modules and hardware acceleration are disabled. You can try disabling you modules one by one to see if that helps, or you can disable hardware acceleration by doing the following:

    Try disabling graphics hardware acceleration. As this feature has been added to Firefox, it has gradually improved, but there are still some problems.

    You will have to perhaps restart Firefox for it to take effect, so save any work first (e.g. you compose mail, documents online that you are editing, etc.).

    Then perform the following steps:

    • Click on the orange top left Firefox button, then select the 'Options' button, or, if there is no Firefox button at the top, go to tools > Options.
    • In the Firefox options window, click the Advanced tab, and then select 'General '.
    • You will find in the list of parameters, the checkbox use hardware acceleration when available . Clear this check box.
    • Now restart Firefox and see if the problems persist.

    In addition, please check the updates for your graphics driver by following the steps in the following knowledge base articles:

  • Hide icon Label step using the API Testand and LabVIEW

    Hello

    can someone tell me how it is possible to hide the icon of a step label using the API Testand and LabVIEW?

    In the Teststand sequence editor, under the Label Edit tab there is a checkbox called "Hide icon". Is there something similar in the API?

    Thank you

    Yes you can, you must set the stage "ni_blank.ico" IconName property

  • How to replace the LabVIEW icon in the upper left corner of the panels?

    Hey Gang,

    We will create an application that will go to customers.  We want to replace the LabVIEW icon in the upper left of the panels with the company logo.  How can I replace that?

    All responses will be appreciated.

    Thanks in advance,

    Roger

    Create the icon you want to there are several editors of ico on the market (I usually use one of the freebies) and save it in your project.

    In the Application build spec select the icon section, clear the default checkbox and choose your .ico in the pop-up.

  • In the notification area, volume, network and power icons have disappeared.

    In the notification area, volume, network and power icons have disappeared. When I go into properties, in the area of system icons the same selections are grey, when I click on them that no check mark. How to make the grey selections to become black (active), so when I click on them the check marks appear?

    [Moved from comments]

    Johnny D.81 responded on November 2, 2012

    Try these steps and check if that helps:

    ** Turn it back on. Sometimes a reboot will solve this problem.* *.

    1. close all programs and stop the laptop.

    2. remove all power supplies (battery and power cord)

    3. empty the remaining power by pressing the power on button for 30 seconds (even if you have no power).

    4. put the battery back and start the computer

    5. once fully loaded, right-click on the system tray and select Properties.

    6. This will bring to the top of the "Taskbar and Start Menu Properties" dialog box. The "Notification area" tab.

    7. at the bottom of the tab, is the area 'icons systems. " There is a checkbox for "Power". "check" the box and click on apply or OK.

    Also update your graphics card drivers.

    It works! Tanks a lot Johnny D.81!

  • No visible Internet Tv icon on Windows Media

    I have a windows 7 and Windows media doesn't have the internet TV icon availble. My wifes computer is running Vista and Internet TV works fine. My daughter also has windows 7 and no internet TV. How can I get my new computer running windows 7 for internet TV? I tried the download tasks - no chance. Any ideas would be appreciated.

    Thank you!

    Hi Mstalford,

    Method 1:

    First, try these steps.

    a. click the Start button, click all programs and then click Windows Media Center.
    b. on the Windows Media Center start screen, go to the TV and then click on Internet TV.

    If this is the first time that you opened Internet TV, you will need to install the service before using it. Click on the checkbox and then click on install.

    c. scroll down, to the left or right to navigate TV shows, movies and other videos until you find something you want to watch and click on it.

    You may need to install additional software, depending on the service you choose. Click on the checkbox and then click on install.

    Method 2:

    I suggest you try these steps provided below and launch internet TV.

    a. open Windows Media Center
    b. navigate to tasks, and then click settings
    c. click on general
    d. click Windows Media Center Setup
    e. click on run the installation again

    Try again with the Express or custom computer Installer.

    Method 3:

    Try following the steps in the link provided below.

    http://www.Microsoft.com/Windows/Windows-Media-Center/get-started/Internet-TV.aspx

    Reference:

    http://www.Microsoft.com/Windows/Windows-7/features/Internet-TV.aspx

    Thank you, and in what concerns:
    I. Suuresh Kumar - Microsoft technical support.

    Visit our Microsoft answers feedback Forum and let us know what you think.

  • How to get "Internet Checkers" back on the desktop with an icon?

    Original title: How can I "INTERNET draughts" _A game I still had on my desk back when I search it does not find the program that is the play area, but no matter what I can't get it back

    I used to play the original game on my computer every day, I even had an icon dedicated to it on the right side with all the other icons on the blank screen, it turns out that since I am disconnected from a router to another router I have more icon of the familia which shows a blue chip Checkers game & where the icon used to be there is an icon that looks like a miniature 'windows' (with the small blue border along the top from left to right), the same size as the other icons, and instead of internet checkers it says: "chkrz.ex" I do not know, but it is a similar term, but he wwas exactly & it's gone now.  How can I get it back to my windows xp computer?

    Hi EddieQuing,
     
    It would be possible that the shortcut for the game has been corrupted.
     
    Check if the game is available in "all programs". If so, create a new shortcut.
    a. click Start. Click "all programs."
    b. click on games. Highlight on draughts of the Internet and click on send to and choose Destop (shortcut).
     
    Check if that helps.
     
    If that's not enough, and if the game is not available at this location, follow these steps to see if the game has been turned off and activate the same.
     
    a. click the Start button, click Control Panel, click on Add / Remove Programsand then click Add or remove Windows components in the left pane.
    b. now in the Windows Components Wizard select the check box for Accessories and utilities-> click Details-> Select the CheckBox games and double click on it and in the list of games that appears, check the box for 'online games', click OK.
    c. click OK twice.
    d. restart the computer now and check.
     
    Keep me updated on the status of the issue.

Maybe you are looking for

  • How Long should it take to transfer data to the new iPhone

    I had a capacity of 32GB iPhone 5 c that I had used about 30 GB of.  Got a new 6 iPhone with a capacity of 64 GB and after a few false starts, I am now transfer data from the old phone to the new by using iTunes.  However, it was 'Step 5 of 5' sync o

  • No Option start secure on Portege Z930-138

    My daughter has been using the PC above the other day when suddenly it would boot is no longer. Now I tried to do a system restore to a backup that I did a few weeks ago, but the system reports that the computer uses the BIOS, but the backup was perf

  • Storage and Application problems

    My software storage are weird, my application used 52GB but my overview of storage shown 290GB. How is it?(IMAGE BELOW)

  • Calibration of color changes after reboot Satellite A660

    I have the Satellite A660 with NVDI G330. The problem is that I set the calibration of color I want and yet when I reboot back to the original setting so I have to readhust it... What should I do?

  • HP 15 ab 522: loud noise of HARD drive

    My laptop (HP 15 ab 522) HARD drive makes squealing noise whenever the HARD drive light flashes white. The noise becomes quite noticeable and persistent when the system boots, the HARD drive light turns to solid white color. HARD drive runs smoothly