Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: JCheckBox help is this possible?

  1. #1
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default JCheckBox help is this possible?

    i have a JCheckBox on my GUI and i want it to look like this

    cboxexample.JPG

    is there a way i can make it blue under only the letters? i tried setbackground(Color.BLUE) but it makes the color go all the way around where the check mark and such is too but i only want it to go under the letters like that not the whole thing...so is this possible? i looked at the JCheckBox api but i didnt find anything that would let me put the color under the text or am i missing it?


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,360
    My Mood
    Hungover
    Thanks
    144
    Thanked 626 Times in 537 Posts

    Default Re: JCheckBox help is this possible?

    The quick and dirty solution would be to just use a JLabel and a JCheckBox with no text and slap them into a JPanel. There's probably a better way though.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    derekxec (September 12th, 2011)

  4. #3
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: JCheckBox help is this possible?

    that will work thanks

  5. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,360
    My Mood
    Hungover
    Thanks
    144
    Thanked 626 Times in 537 Posts

    Default Re: JCheckBox help is this possible?

    Actually the one thing that'll miss is clicking on the text to change the status of the check box. That's just a MouseListener though.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  6. #5
    Member
    Join Date
    Sep 2011
    Location
    United States
    Posts
    30
    My Mood
    Fine
    Thanks
    0
    Thanked 6 Times in 5 Posts

    Default Re: JCheckBox help is this possible?

    There is a way to do this by using java.awt.font.TextAttribute and java.util.Map. This way you won't need a MouseListener. The general form, I believe would be like this:

    Map<TextAttribute, Color> attributes = new Hashtable<TextAttribute, Color>();
    attributes.put(TextAttribute.BACKGROUND, Color.YELLOW);
    component.setFont( new Font(attributes) );

    You may need to play around with it a bit but that should help you out.


    EDIT: So I changed the code a bit and it seems Ok now. I got the code, basically, from Oracle
    Last edited by SerratedMind; September 12th, 2011 at 03:07 PM.

  7. The Following 2 Users Say Thank You to SerratedMind For This Useful Post:

    derekxec (September 12th, 2011), KevinWorkman (September 13th, 2011)

  8. #6
    Member
    Join Date
    May 2011
    Location
    west palm beach, FL
    Posts
    189
    My Mood
    Tired
    Thanks
    41
    Thanked 11 Times in 10 Posts

    Default Re: JCheckBox help is this possible?

    thanks and that link has some other stuff i can use too

Similar Threads

  1. How to implement JCheckBox inside JButton?
    By s1w in forum AWT / Java Swing
    Replies: 2
    Last Post: September 16th, 2011, 12:18 PM