public class TestLabelBox extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel panel1 = new JPanel();
private Color color1 = new Color(0,0,255);
private Color color2 = new Color(0,255,0);
private Color color3 = new Color(255,0,0);
public TestLabelBox(){
super();
panel1.setLayout(new FlowLayout(FlowLayout.LEFT));
panel1.add(new MyLabel(color1,"A "));
panel1.add(new MyLabel(color2,"B "));
panel1.add(new MyLabel(color3,"C "));
add(panel1);
// this.pack();
}
/**
* @param args
*/
public static void main(String[] args) {
run(new TestLabelBox(),200,100);
}
}
class MyLabel extends JLabel
{
private Color color;
private int width = 16;
private int height = 13;
private int x = 20;
private int y = 2;
public MyLabel(){
super();
}
public MyLabel(Color color,String text){
super(text);
// setSize(4000, 25);
// setBounds(new Rectangle(27, 25, 42, 15));
this.color=color;
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(color);
g.drawRect(x, y, width, height);
}
}
private static final long serialVersionUID = 1L;
private JPanel panel1 = new JPanel();
private Color color1 = new Color(0,0,255);
private Color color2 = new Color(0,255,0);
private Color color3 = new Color(255,0,0);
public TestLabelBox(){
super();
panel1.setLayout(new FlowLayout(FlowLayout.LEFT));
panel1.add(new MyLabel(color1,"A "));
panel1.add(new MyLabel(color2,"B "));
panel1.add(new MyLabel(color3,"C "));
add(panel1);
// this.pack();
}
/**
* @param args
*/
public static void main(String[] args) {
run(new TestLabelBox(),200,100);
}
}
class MyLabel extends JLabel
{
private Color color;
private int width = 16;
private int height = 13;
private int x = 20;
private int y = 2;
public MyLabel(){
super();
}
public MyLabel(Color color,String text){
super(text);
// setSize(4000, 25);
// setBounds(new Rectangle(27, 25, 42, 15));
this.color=color;
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(color);
g.drawRect(x, y, width, height);
}
}