[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Creating a block of color

Posted on 2004-09-08
9
Medium Priority
?
250 Views
Last Modified: 2010-03-31
Hi all,

I am writing a key for a graph and want to have a list of decriptions, preceeded by a square block of color. ie:

[BLACK] ....some text
[RED] ... some text
[BLUE] ... some text

Whats the best way to add a colored square to a JPanel so that it lines up with some text?
0
Comment
Question by:agrees
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 37

Expert Comment

by:zzynx
ID: 12006618
Use three JLabels and set as label icon a gif of a square block of the wanted color
0
 
LVL 92

Accepted Solution

by:
objects earned 200 total points
ID: 12006630
Use a panel for your square block and set its colour and size.
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12006631
See http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JLabel.html (especially the setIcon() function)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 92

Expert Comment

by:objects
ID: 12006654
JPanel p = new JPanel();
p.setBackground(Color.red);

then add the panel to your container using the required layout.

0
 
LVL 92

Expert Comment

by:objects
ID: 12006679
BoxLayout would seem the best, and set the maximum size of the panel

panel.setMaximumSize(new Dimension(w, h));
0
 

Author Comment

by:agrees
ID: 12009099
Using a JPanel seems to be the simplest way and it works, thanks!
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12009205
   getContentPane().setLayout(new FlowLayout());
    JLabel labRed = new JLabel("\u220e");
    labRed.setForeground(Color.red);
    JLabel labRedDesc = new JLabel(" This is the red key");
    getContentPane().add(labRed);
    getContentPane().add(labRedDesc);
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12009210
Not simpler than that ;-)
0
 
LVL 92

Expert Comment

by:objects
ID: 12012080
> Using a JPanel seems to be the simplest way and it works, thanks!

your welcome :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question