Results 1 to 3 of 3
  1. #1
    anindde is offline Member
    Join Date
    Nov 2009
    Posts
    1
    Rep Power
    0

    Default Not able to display icon with JCheckBox

    So this is a snippet code I am using:

    class BarPanel extends JPanel {

    URL iconURL = Test.class.getResource("caper.jpg");
    ImageIcon caper = new ImageIcon(iconURL);
    JCheckBox check1 = new JCheckBox("Check 1", caper,true);


    public BarPanel() {
    setLayout(new FlowLayout());
    add(check1);
    }
    }

    The image shows up fine but I can't see a checkbox, only the image icon with the Label. If I define the JCheckBox instance without an icon, the checkbox appears just fine.

    Any help would be appreciated.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Are you trying to shove this panel into too small a location? Without a small compilable program that demonstrates your problem, it's going to be difficult to tell what you're doing wrong.

  3. #3
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Posts
    1,226
    Rep Power
    6

    Default

    The check box is an Icon, so when you use the setIcon method you are actually replacing the existing icon.

    Darryl's Toggle Button Icons solution might be what you are looking for.

Similar Threads

  1. JCheckbox in Jtree
    By shajuantony in forum AWT / Swing
    Replies: 10
    Last Post: 09-09-2009, 10:42 AM
  2. can java program display icon on unix?
    By java2008 in forum Advanced Java
    Replies: 1
    Last Post: 10-06-2008, 07:33 AM
  3. Issue with Jcheckbox on JTableheader
    By ram_76uk in forum AWT / Swing
    Replies: 2
    Last Post: 07-30-2008, 08:24 AM
  4. Can we add JCheckBox array into JTextArea?
    By nancyhung in forum AWT / Swing
    Replies: 1
    Last Post: 02-17-2008, 12:07 AM
  5. jcheckbox issues need help. thanks.
    By carlos123 in forum New To Java
    Replies: 3
    Last Post: 11-05-2007, 10:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •