Results 1 to 6 of 6
  1. #1
    goatjugsoup is offline Member
    Join Date
    May 2012
    Posts
    15
    Rep Power
    0

    Default [SOLVED] How would you go about adding text and images to a button or label?

    I am trying to do something like what I have posted below in that image where the 1s are variables I would want to be able to change at runtime and the colored squares are images. I was thinking this might be done on a button or label with image icons or something similar, the images will not need to be changed, just the variables. I am not even sure if this could be done on 1 button or label or if it needs to be done on 3.
    Any help would be appreciated



    *edit*
    As a sidenote, if anyone could tell me how to size an image programmatically that would also be very helpful, as it is I have just been resizing with fireworks.
    Last edited by goatjugsoup; 05-21-2012 at 10:19 AM.

  2. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: How would you go about adding text and images to a button or label?

    The JButtons and Jabels have a setText( ... ) and setIcon( ... ) method together with a couple of allignment methods. Don't they suffice?

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    goatjugsoup is offline Member
    Join Date
    May 2012
    Posts
    15
    Rep Power
    0

    Default Re: How would you go about adding text and images to a button or label?

    I have been looking at those and if I end up having to use 3 different buttons, 1 for each paring of text and image that method will work but as far as I know the setIcon won't allow you to have multiple icons. I'm really hoping there's a better way that I just don't know about but thanks for the reply.

  4. #4
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: How would you go about adding text and images to a button or label?

    Rob Camick has a site full of tips and tricks; one of them describes how you can create a single Icon out of two (or more) Icons so you can stick them in a JLabel or JButton. Note that this isn't the only solution for displaying several Icons in a row ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    goatjugsoup is offline Member
    Join Date
    May 2012
    Posts
    15
    Rep Power
    0

    Default Re: How would you go about adding text and images to a button or label?

    The link you provided looks interesting but I couldn't see anything there that would achieve what I wanted to do. I have messed around with 3 different labels and have gotten it to look as if I were doing it with 1 which is what I was trying to do so I guess thats good enough. Thanks for the tips anyway, the knowledge will probably help me out down the line.

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,435
    Blog Entries
    7
    Rep Power
    20

    Default Re: How would you go about adding text and images to a button or label?

    Quote Originally Posted by goatjugsoup View Post
    The link you provided looks interesting but I couldn't see anything there that would achieve what I wanted to do. I have messed around with 3 different labels and have gotten it to look as if I were doing it with 1 which is what I was trying to do so I guess thats good enough. Thanks for the tips anyway, the knowledge will probably help me out down the line.
    I gave you the link to the home page so you could bookmark it (it's worth it); I expected you to be able to find the topic yourself.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 3
    Last Post: 12-05-2011, 01:28 PM
  2. unicode ok for text pane but not for button label
    By madroadbiker in forum Advanced Java
    Replies: 6
    Last Post: 06-01-2011, 05:58 PM
  3. adding label to the anel of other class
    By saranyabaskaran in forum New To Java
    Replies: 6
    Last Post: 03-25-2011, 08:12 AM
  4. Adding a sqrt button and percentage button to a calculator
    By Josie_Taylor in forum New To Java
    Replies: 4
    Last Post: 03-14-2011, 01:16 AM
  5. Replies: 1
    Last Post: 08-16-2010, 10:49 AM

Posting Permissions

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