Deepu James

Greenhorn
+ Follow
since Oct 27, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Deepu James

Hello,

I have tried Sttexthorrizonatl and Vertical alighnment. But still I am not able display text over the icon and postion it correctly according to my needs. Anyway thats for your help.
15 years ago
hi see th efollowing code which code of multi ICon class chechi can display multiple icons over JLabel. Now I want display Text..( image numbers ) over the icons. with Jlabel setText() i am not able to postion it correctly. Is there any way to display image unumber(SetText()) below or over the icons Added over a Jlabel.

Any sample code is highly appricated.

here is the code of MultiIcon I am using
package ateportal;

import java.awt.Component;
import java.awt.Graphics;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

/**
*
* @author deepuj
*/
public class MultiIcon implements Icon {

public static final int ALIGNMENT_HORIZONTAL = 1;
public static final int ALIGNMENT_VERTICAL = 2;
public static final int ALIGNMENT_STACKED = 3;

public ImageIcon thumbNail1 = null;
public ImageIcon thumbNail2 = null;
public ImageIcon thumbNail3 = null;

public ImageIcon boxPosIcon1 = null;
public ImageIcon boxPosIcon2 = null;
public ImageIcon boxPosIcon3 = null;
private int gap = 3; // will be ignored for stacked alignment

private Icon[] icons;
private int alignment;
private int width = 0;
private int height = 0;

public MultiIcon() {
this(ALIGNMENT_HORIZONTAL);
}

public MultiIcon(int alignment) {
this.alignment = alignment;
}

public int getIconCount() {
if (icons == null) {
return 0;
} else {
return icons.length;
}
}

public Icon getIconAt(int index) {
return icons[index];
}

public int getIconAt(int x, int labelx) {
//int y = point.y;
int firstIconWidth = getIconAt(0).getIconWidth();
//JOptionPane.showMessageDialog(null, "firstIconWidth = " +firstIconWidth);
int secondIconWidth = getIconAt(1).getIconWidth();
int thirdIconWidth = getIconAt(2).getIconWidth();
int fourthIconWidth = getIconAt(3).getIconWidth();
int fifthIconWidth = getIconAt(4).getIconWidth();
//JOptionPane.showMessageDialog(null, "fourthIconWidth = " +fourthIconWidth);
//JOptionPane.showMessageDialog(null, "fifthIconWidth = " +fifthIconWidth);
if (x - labelx > 0) {
if (x - (labelx + firstIconWidth) > 0) {
if (x - (labelx + firstIconWidth + secondIconWidth+(gap*1)) > 0) {
if (x - (labelx + firstIconWidth + secondIconWidth + thirdIconWidth+(gap*2)) > 0) {
if (x - (labelx + firstIconWidth + secondIconWidth + thirdIconWidth + fourthIconWidth+(gap*3)) > 0) {
if (x - (labelx + firstIconWidth + secondIconWidth + thirdIconWidth + fourthIconWidth+ fifthIconWidth +(gap*4)) > 0){
//outside
return 0;
}else{
return 5;
}

} else {
return 4;
}

} else {
return 3;
}

} else {
return 2;
}

} else {
return 1;
}

} else {
return 0;
}

}
// public int getIconAt(int x, int y, int labelx, int labely) {
// //int y = point.y;
// int firstIconWidth = getIconAt(0).getIconWidth();
// int secondIconWidth = getIconAt(1).getIconWidth();
// int thirdIconWidth = getIconAt(2).getIconWidth();
// int fourthIconWidth = getIconAt(3).getIconWidth();
// int fifthIconWidth = getIconAt(4).getIconWidth();
//
// if (x - labelx > 0) {
// if (x - (labelx + firstIconWidth) > 0) {
// if (x - (labelx + firstIconWidth + secondIconWidth+(gap*1)) > 0) {
// if (x - (labelx + firstIconWidth + secondIconWidth + thirdIconWidth+(gap*2)) > 0) {
// if (x - (labelx + firstIconWidth + secondIconWidth + thirdIconWidth + fourthIconWidth+(gap*3)) > 0) {
// if (x - (labelx + firstIconWidth + secondIconWidth + thirdIconWidth + fourthIconWidth+ fifthIconWidth +(gap*4)) > 0){
// //outside
// return 0;
// }else{
// return 5;
// }
//
// } else {
// return 4;
// }
//
// } else {
// return 3;
// }
//
// } else {
// return 2;
// }
//
// } else {
// return 1;
// }
//
// } else {
// return 0;
// }
//
// }

public void replaceIconAt(int index, Icon newIcon) {
icons[index] = newIcon;
width = calculateIconWidth();
height = calculateIconHeight();
}

public void addIcon(Icon icon) {
if (icon == null) {
return;
} else {
if (icons == null) {
icons = new Icon[]{icon};
} else {
Icon[] newIcons = new Icon[icons.length + 1];
System.arraycopy(icons, 0, newIcons, 0, icons.length);
newIcons[newIcons.length - 1] = icon;
icons = newIcons;
}
width = calculateIconWidth();
height = calculateIconHeight();
}
}

public void paintIcon(Component c, Graphics g, int x, int y) {
if (icons == null) {
return;
} else if (alignment == ALIGNMENT_VERTICAL) {
int yIcon = y;
for (int i = 0; i < icons.length; i++) {
Icon icon = icons[i];
int xIcon = x + (width - icon.getIconWidth()) / 2;
icon.paintIcon(c, g, xIcon, yIcon);
yIcon += icon.getIconHeight() + gap;
}
} else if (alignment == ALIGNMENT_STACKED) {
for (int i = 0; i < icons.length; i++) {
Icon icon = icons[i];
int xIcon = x + (width - icon.getIconWidth()) / 2;
int yIcon = y + (width - icon.getIconWidth()) / 2;
icon.paintIcon(c, g, xIcon, yIcon);
}
// for (int i = 0; i < icons.length; i++) {
// Icon icon = icons[i];
// int xIcon = x;
// int yIcon = y;
// if(i==1)
// {
// xIcon = x ;
// yIcon = y + (icon.getIconHeight()) / 2 + (icon.getIconHeight()) / 3 + (icon.getIconHeight()) / 3;
// icon.paintIcon(c, g, xIcon, yIcon);
// }
// else{
// //Icon icon = icons[i];
// // yIcon =y;
// xIcon = x + (width - icon.getIconWidth()) / 2;
// icon.paintIcon(c, g, xIcon, yIcon);
// yIcon += icon.getIconHeight() + gap;
// }
//
//
// }
} else {
assert alignment == ALIGNMENT_HORIZONTAL;
ImageIcon left = new ImageIcon("C:\\Documents and Settings\\Deepu James\\Desktop\\1.png");
int xIcon = x;
for (int i = 0; i < icons.length; i++) {


//yIcon = y + (height - icon.getIconHeight()) / 2;
//end of code
Icon icon = icons[i];
int yIcon = y -10 ;//+ (height - icon.getIconHeight()) / 2;
icon.paintIcon(c, g, xIcon, yIcon);
// code
// if(i!=0 && i!=4)
// {
// //yIcon = y;
// //xIcon = x;
// Icon icon1 = null;
// if (i==1)
// icon1 =this.boxPosIcon1;
// else if(i==2)
// icon1 =this.boxPosIcon2;
// else if(i==3)
// icon1 =this.boxPosIcon3;
// yIcon = yIcon + icon.getIconHeight()+3;
// int dx = xIcon + icon.getIconWidth()/2 - icon1.getIconWidth()/2;
// icon1.paintIcon(c, g, dx, yIcon);
// }
xIcon += icon.getIconWidth() + gap;
}

}
}

public int calculateIconWidth() {
if (icons == null) {
return 0;
} else if (alignment == ALIGNMENT_HORIZONTAL) {
int width = 0;
for (int i = 0; i < icons.length; i++) {
width += icons[i].getIconWidth();
}
width += gap * (icons.length - 1);
return width;
} else {
int width = 0;
for (int i = 0; i < icons.length; i++) {
width = Math.max(width, icons[i].getIconHeight());
}
return width;
}
}

public int calculateIconHeight() {
if (icons == null) {
return 0;
} else if (alignment == ALIGNMENT_VERTICAL) {
int height = 0;
for (int i = 0; i < icons.length; i++) {
height += icons[i].getIconWidth();
}
height += gap * (icons.length - 1);
return height;
} else {
int height = 0;
for (int i = 0; i < icons.length; i++) {
height = Math.max(height, icons[i].getIconHeight());
}
return height;
}
}

public int getIconWidth() {
return width;
}

public int getIconHeight() {
return height;
}
}
15 years ago
It is not problem to display text over another component... I dont care whether it would be transperant or not. I want to plce image numbers over images displayed. The only problem is postioning text in the desired location.

Thanks very much for your help

Kind Regards
DJ
15 years ago
How to do it? Do you have any code sample to do it

Thank you very much for a quick reply.
15 years ago
Hi,

I have Jlabel with mutiple icons over it. I have created a new class extending Icon to achive this. Now I would like to display the icon image number over the image. Is there any option of Extending setText to diplay text over image icon in a Jlabel to display it in correct x, y coordinates?

Thanks
DJ
15 years ago
Hello,
I have JLabel displayed on one of my JTable cells. One of the label has Icon image displayed over it. I would like to display arrow button on mouse over Jlabel and displat next ImageIcon on the label when I click on the arrow.
How can I diplay small arrows over a Jlabel Image component when mouse is moved over it? Any help or sample code for this would be very helpfull

Thanks
DJ
15 years ago