• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Using images within a JPanel

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I am drawing a menu bar on the side of a canvas. I have a series of JLabels describing what various key strokes do.
However below this I would like to draw a key showing what colours in the canvas represent.
Is there any way that I have do something where I have a small image then beside it some text describing what the color represents?
Say the box below is the JPanel...

|----------------�
|<image><JLabel> |
|<image><JLabel> |
|<image><JLabel> |
|<image><JLabel> |
| |
| |
| |
|_________________|
This is the effect that I would like to get.
Thanks.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can make the icon yourself by just by making a class that implements Icon and takes a Color, and just paints a rectangle of that color in the paintIcon() method. JLabels can have both text and an Icon, so you can just set them both in a JLabel. The default is for the icon to be on the left of the text on the label, so you won't have to mess with setting any of that differently.
 
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic