CheckBox - how to set custom icons

I need to figure out how to set a custom icon for a selected checkbox via the UIManager
This works for un-selected checkboxes:
UIManager.put("CheckBox.icon", new ImageIcon("../images/unselectedCheckBoxIcon.png")));
how to change the icon when it is selected?
I don't know the UIManager property for a selected checkbox icon and using the setSelectedIcon on the checkbox object it self does not seem to work:
checkbox.setSelectedIcon(new ImageIcon("../images/selectedCheckBoxIcon.png"));
Thanks for any ideas how to solve this!!

Hi mKorbel, many thanks for your suggestion!
For anyone interestsed,
here is a small example of how I made it working.
Unfortunately I cannot attatch the icon images that I use, but the selected icon can be downloaded from here, resize it to 32*32, remove the cross in the middle to save it as the unselected icon.
* Modified sample code taken from here
* http://www.java2s.com/Tutorial/Java/0240__Swing/CustomizingJCheckBoxCheckMarkIcon.htm
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.net.URL;
import javax.swing.AbstractButton;
import javax.swing.ButtonModel;
import javax.swing.Icon;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
public class IconCheckBoxSample {
  public static void main(String[] args) {
        JFrame frame = new JFrame("Iconizing CheckBox");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Icon checked = new CheckBoxIcon();
        Icon unchecked = new CheckBoxIcon();
        JCheckBox aCheckBox1 = new JCheckBox("Pizza", unchecked);
        aCheckBox1.setSelectedIcon(checked);
        JCheckBox aCheckBox2 = new JCheckBox("Calzone");
        aCheckBox2.setIcon(unchecked);
        aCheckBox2.setSelectedIcon(checked);
        Icon checkBoxIcon = new CheckBoxIcon();
        JCheckBox aCheckBox3 = new JCheckBox("Anchovies", checkBoxIcon);
        JCheckBox aCheckBox4 = new JCheckBox("Stuffed Crust", checked);
        frame.setLayout(new GridLayout(0,1));
        frame.add(aCheckBox1);
        frame.add(aCheckBox2);
        frame.add(aCheckBox3);
        frame.add(aCheckBox4);
        frame.setSize(300, 200);
        frame.setVisible(true);
class CheckBoxIcon implements Icon {
  public void paintIcon(Component component, Graphics g, int x, int y) {
    AbstractButton abstractButton = (AbstractButton)component;
    ButtonModel buttonModel = abstractButton.getModel();
    if(buttonModel.isSelected()) 
        g.drawImage(createImage("../images/selectedCheckBoxIcon.png","info"), x, y, component);
    else
        g.drawImage(createImage("../images/unselectedCheckBoxIcon.png","info"), x, y, component);
  public int getIconWidth() {
    return 33;
  public int getIconHeight() {
    return 33;
  protected static Image createImage(String path, String description) {
        URL imageURL = CheckBoxIcon.class.getResource(path);
        Image icn = null;
        if (imageURL == null) {
            if(null==icn){
                //System.out.println("path: "+path);
                icn = new ImageIcon (CheckBoxIcon.class.getResource(path.replace("..",""))).getImage();
                if(null!=icn)
                    return icn;
                else{ 
                    System.err.println("Resource not found: " + path);
                    return null;
             return null;
        } else {
            return (new ImageIcon(imageURL, description)).getImage();

Similar Messages

  • How to set custom font family in qml label in black berry 10 os

    how to set custom font family in label text  qml in black berry 10 OS

    AFAIK, this is not the correct way to set the image location.
    We call the working directory as context, so inside the context root along with WEB-INF, maintain a folder with name img and put all the images in that directory.
    You can use either .\<image_folder> or the optimum way would be (if you are using JSPs) to use getContext() method and traverse accordingly.
    FYI,,, using getContext() will give you context root directory, from there it is as simple as accessing any other folder.
    Hope this answers your question.
    Cheers,
    Jeets.

  • How to set custom master page for social/sites.aspx in sharepoint 2013

    How to set custom master page for social/sites.aspx in sharepoint 2013.?
    File path is
    C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\FEATURES\SocialDataStore\SocialDataStoreList\sites.aspx
    Thanks in advance

    Hi,
    You could open the sites.aspx in Notepad or SharePoint designer, and set the master page to your own master page directly via editing:
    <%@ Page language="C#" MasterPageFile="~masterurl/custom.master"      Inherits="Microsoft.SharePoint.Portal.WebControls.FollowedContentWebPartPage,Microsoft.SharePoint.Portal,Version=15.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c"
    %>
    Regards,
    Rebecca Tu
    TechNet Community Support

  • How to set custom size of Close Button e.g. 32x32  of Title Window in Flex 4

    How to set custom size of Close Button e.g. 32x32 of Title Window in Flex 4?

    Hi
    Here is the code of the Button in the skin class of spark title window.
    <s:Button id="closeButton" skinClass="spark.skins.spark.TitleWindowCloseButtonSkin"
                              width="15" height="15" right="7" top="7" />
    So first change the default height and width from 15 to 32. Then in the Button Skin class i.e. spark.skins.spark.TitleWindowCloseButtonSkin change paths to modify the cross symbol.
    Hope this helps
    Rush-me

  • How to set different Icons for Jtreenode

    How to set different Icons for Jtreenode,i want to set icons for jtreenode,not only for leaf,open,closeicon,i hope that each node has a different icon.Thanks!

    you need to check for the node value within a renderer, then assign an icon based on what you expect to get back.
    check out this page. http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html

  • How to set different icons for different windows which is seen in the top left corner?

    Hi
    How to set different icons for different windows which is seen in the top left corner? I know when building exe there is a option to edit icons or add icons and that icon is default for all the windows in the project. But i want different icons for different windows which is possible in VB.
    Is there any way to set icon by calling any dlls.
    Thanks & Regards
    Samuel J
    [email protected]

    Hi Sam,
    no problem. See the attachment.
    Mike
    Attachments:
    TestIcon_LV85.zip ‏44 KB

  • How to set image icon to JFrame

    Hi all,
    how to set image icon in the title bar of JFrame
    Thank for your help in advance

    thanks
    I have done as:
    Image image;
    image=getToolkit().getImage("database_yellow.png");
    if(image==null)System.out.println("fault
    n("fault image");
    this.setIconImage(image);
    but when I run my application, I can't see the database_yellow.png in the
    title barHm, strange ... from the code snippet you just posted I can't find the error.
    This may seem weird, but try to load a small .gif image instead ...
    Are you sure the Image is not equal to null?
    kind regards,
    Jos

  • How to set Custom HTTP headers in HTTP binding?

    How to set custom HTTP headers before sending the Rest based request in HTTP binding?

    sharon38_74 wrote:
    they said that our internal application needs to send a "login request" to etran via SSL with the user's information encoded in base 64 format. etran captures the HTTP header containing user authentication and authorization information, and parses the required information from the HTTP header.
    My question is that how I set user information in HTTP header? From my understanding, once I am able to set the user information in HTTP header, it is in base 64 format?Your application need to act like a proxy. You can invoke a HTTP request programmatically using java.net.URLConnection. You can set request headers using URLConnection#setRequestProperty(). Also see the API docs: [http://java.sun.com/javase/6/docs/api/java/net/URLConnection.html]. You only need to know the header field name where to set the Base64-encoded value in. You need to Base64-encode the value yourself.

  • CR 2008 SDK: how to set custom paper size?

    Dear forum users, I'm trying to use Crystal Reports 2008 SDK to print barcode labels to a Datamax Printer.
    The printer uses a custom page size. Can anyone tell me how to set custom page size and margins using C# and CR2008 SDK?
    Best regards
    Alessandro

    I'm experiencing this problem: I need to print barcode labels which are 4 x 9 cm each (a custom paper size). The report has been build correctly, orientation is right but when I print the labels programmatically by an application I made the label gets printed in a wrong way.
    In particular, orientation and paper size are not correct.
    So I would like to try to force both of them (both the orientation and the custom paper size). How can I do that?
    Best regards
    Alessandro

  • How to set the icon for the entire application with JFrame.setIconImage

    I set the icon on the main frame using JFrame.setIconImage(). The icon is shown properly in the main frame.
    If more JFrames are opened from the main frame, the newly opened JFrames also show the icon.
    However if JDialogs are opended, in some cases the icon set on the main frame is shown and in other cases the coffee cup.
    What is JFrame.setIconImage() expected to do? Setting the icon for a single JFrame or the entire application?
    How can I set the icon for the entire application?
    How can I set the icon for JDialogs?
    Thank you

    In order for your dialogs to use the same icon as the frame, you must parent the dialogs to the frame which has the custom icon.
    See the following thread for more information: http://forum.java.sun.com/thread.jsp?forum=57&thread=362542
    cheers,
    Greg

  • How to set folder icon image in OS X Lion?

    I set my folder's icon image in OS X Leopard before, but I don't know how to do that in Lion.  In Leopard you simply copy the icon image from an Info window of a file, and paste that into the folder's icon image in the top left corner of its Info window.  In Lion I don't see the icon of the file in its Info window as a preview, but rather I see only a generic JPG file icon.  Any ideas?

    Can you explain why there was no thumbnail for that file?
    The OS does not create or add thumbnails, previews, nor custom icons to images or other files. Although it displays files with what appears to be a custom icon, it is not part of the file itself; it is created on the fly, just for display. Since it is not part of the file, it does not appear in the Get Info window.
    Back in OS 9 days when you downloaded an image file from the web, either via drag and drop or via the download mechanism, the image file would typically be placed on the drive as a QuickTime image with both a custom icon and a preview image added to it.
    I skipped earlier versions of OS X, and started with Snow Leopard, so don't know about earlier versions of OS X. Apparently the auto creation and addition of a custom icon and preview have been dropped in later versions in favor of using Preview to generate a temporary (for display only) custom icon on the fly. One result of this is that image file sizes are kept reasonably small - adding a suite of custom icons and a preview image to the file itself increases the file size a lot; it's not unusual for those additions to double the file size, or more.

  • 10.6.6 - How to set custom view options for specific folders

    How is it that Windows has had the ability to ability to set custom folder view options forever and OSX can't. What is the big deal? Just do it. Whenever I set the folder view options it changes the view for all the folders. I can do folder specific changes as long as the finder window is open then I close it and open it again every folder is the same again. It's just an annoyance and it's something so rudimentary it's embarrassing.

    Try the following:
    I want to have, say, one folder in list view
    Open that folder, set it to list view, type command-J, and in the view-options window that opens, check the box at the top for "Always open in list view".
    then the subfolder of that folder I want to have in cover flow view. permanently.
    Open that folder, change it to cover-flow view, and in the view-options window check the box at the top for "Always open in cover-flow."
    Those two folders should "remember" the custom views that were set for them.
    There's additional discussion about the meaning of the"Use as defaults" button in this thread
    http://discussions.apple.com/thread.jspa?messageID=13063792
    My own take is that folders that have not been customized by checking the "Always open in xxx view" box will by default open in the same view (icon vs list vs column, etc) that was in effect for the previously opened folder. *Within each view*, you can set the default parameters (text size, etc) for a new folder by setting up a folder the way you like and then checking the view options box for "Use as defaults" at the bottom.

  • How to set an icon of a Button in ActionScript ?

    A need to create at runtime some buttons and set their icons.
    I found a problem to do that in ActionScript. In MXML is easy
    to set the icon just use a syntax like this: <mx:Button
    label="some text" icon="images/ok.png"/>
    But in ActionScript how I can set the icon ?
    I need to create the icon by a path passed as a parameter.
    Example:
    The user want to create a button with a label and an icon so
    call a method like this (that return and instance of Button):
    createButton("Update","images/update.png");
    Thank at all for the help.
    Marco

    supahsain08 wrote:
    Well i did this
    Triangle.setLocation(50, 100);
    (where Triangle is a buton)
    it doesn't do anything, stays at the same placeIt's all about context here and there are still many unknowns here that can effect your result and that you have not told us or shown us. My suggestion to you is to consider posting an SSCCE (Short, Self Contained, Correct (Compilable), Example, a condensed program similar to your current program in that it demonstrates the problem at hand, but is the smallest bit of code that still compiles and has no extra code that's not relevant to your problem. For more info on SSCCEs please look here:
    [http://homepage1.nifty.com/algafield/sscce.html|http://homepage1.nifty.com/algafield/sscce.html]
    Also, when posting your code, please use code tags so that your code will retain its formatting and be readable. To do this, you can will need to paste already formatted code into the forum, highlight this code, and then press the "code" button at the top of the forum Message editor prior to posting the message. You may want to click on the Preview tab to make sure that your code is formatted correctly. Another way is to place the tag &#91;code] at the top of your block of code and the tag &#91;/code] at the bottom, like so:
    &#91;code]
      // your code block goes here.
      // note the differences between the tag at the top vs the bottom.
    &#91;/code]or
    {&#99;ode}
      // your code block goes here.
      // note here that the tags are the same.
    {&#99;ode}good luck, pete

  • How to set custom master page for sharepoint application page ?

    Hello,
    I need to apply custom master page for the custom application page I created for login purpose.
    Can anyone please let me know how to apply master page for custom application page ?
    Note : I need to set custom master page for application page at web application level.
    thanks,
    Dipti Chhatrapati

    Hi Dipti,
    You can use the same reference as ASP.NET
    Example
    "<%@ Page Language="C#" masterpagefile="../_catalogs/masterpage/minimal.master" title="teste" inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" meta:webpartpageexpansion="full"
    meta:progid="SharePoint.WebPartPage.Document" %>"
    You can use SharePoint Designer 2010
    http://www.microsoft.com/download/en/details.aspx?id=16573 to make the reference from you aspx page to you custom masterpage.
    When you are editing a aspx page you can go to ribbon "Style" and attach the custom Masterpage.
    André Lage Microsoft SharePoint, CRM Consultant
    Blog:http://aaclage.blogspot.com
    Codeplex:http://spupload.codeplex.com/http://simplecamlsearch.codeplex.com/

  • Unable to set custom icon for system drive

    Title says it all. Can't paste new custom icon onto drive icon in the Info panel-nothing happens. Any ideas?

    When a custom icon is applied to a folder (including the "boot drive" icon, which is really just the top level folder), an invisible "Icon\r" file is created inside that folder (or a ".VolumeIcon.icns" in case of a volume - I missed this in the last post, sorry) and the "Custom Icon" file attribute is set. In order to do these things, a user must have sufficient privileges to modify the folder.
    In Leopard, the default permissions are:<pre>
    $ lsbom -d /Library/Receipts/boms/com.apple.pkg.Essentials.bom |grep "^. "
    . 41775 0/80</pre>
    The owner is "root", group is "admin", both have "read & write" privileges, and everyone else has "read only" privileges.
    Similarly, in "Tiger":<pre>
    $ lsbom -d /Library/Tiger/BaseSystem.pkg/Contents/Archive.bom |grep "^. "
    . 41775 0/80</pre>
    Nothing has changed. But furthermore, since the "sticky" bit is set, this might even mean that a custom icon set by one "admin" would only be removable by the same "admin" (though this isn't something I have tested). But either way, at a minimum, "admin" privileges would normally be required.
    So if you had previously modified the permissions on the boot drive to allow non-admins to make changes, then certainly you woudn't have to have "admin" privileges to do this. But that is not the "normal" state.
    Beyond that, it's hard to say why you can't make the changes even as an "admin" without at least knowing what the current permissions are on "/" and "/.VolumeIcon.icns"...

Maybe you are looking for