Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

JLabel and ImageIcon question

Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to applets.
As of now I have the following:
ImageIcon bluePic = new ImageIcon("blue.gif");
JLabel instr = new JLabel("Hello", bluePic, JLabel.CENTER);
The above produces the text i.e. "Hello" next to the image. I would like this Hello to be displayed "on the image itself" and not next to it. Is there any way to achieve this?
I basically have an applet whose label values changes frequently (JMS), thus I would only like to change the text again and again, but would like the text to appear on top of the image and not beside it.
I would be grateful if somebody could help me out.
P.S: One possible solution would be to set the background of the Label (the imageicon is for a blue background). Is there any way to set the background color of a JLabel??
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can set the background of any component. The example below shows with a label.

This tiny ad is suggesting that maybe she should go play in traffic.
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic