ImageIcon replication

Hi,

I want to apply an image as an ImageIcon to a JLable. Size of my lable is Dimension(300,30). I have an image of width 1 pixel and height matching to that of the lable. I want to replicate it and apply for the entire banner as ImageIcon. Any idea how can it be done?

Thanks in advance,

Hrishi

[320 byte] By [new_rishia] at [2007-11-27 5:55:15]
# 1

Yes, and luckily I'm bored enough to whip this up...

public class RepeatIcon implements Icon

{

private Icon icon;

private int direction, size;

public RepeatIcon(Icon icon, int direction, int size)

{

this.icon = icon;

this.direction = direction;

this.size = size;

}

public int getIconWidth()

{

return (this.direction == SwingConstants.HORIZONTAL) ? this.size : this.icon.getIconWidth();

}

public int getIconHeight()

{

return (this.direction == SwingConstants.HORIZONTAL) ? this.icon.getIconHeight() : this.size;

}

public void paintIcon(Component c, Graphics g, int x, int y)

{

g.translate(x, y);

if(this.direction == SwingConstants.HORIZONTAL)

{

int iw = this.icon.getIcontWidth();

for(int i = 0; i < this.size; i+=iw)

{

this.icon.paintIcon(c, g, i, 0);

}

}

else

{

int ih = this.icon.getIconHeight();

for(int i = 0; i < this.size; i+=ih)

{

this.icon.paintIcon(c, g, 0, i);

}

}

g.translate(-x, -y);

}

}

bsampieria at 2007-7-12 15:50:47 > top of Java-index,Desktop,Core GUI APIs...