The easiest way is to combine the two icons into one. You can do this either manually (if you have only few combinations) or write an Icon implementation on your own You can e.g. Align the two icons side-by-side with the following implementation: import java.awt. Component; import java.awt.
Graphics; import javax.swing. Icon; public class DoubleIcon implements Icon { private static final int ICONSPACING = 4; private final Icon i1; private final Icon i2; public DoubleIcon(Icon i1, Icon i2) { this. I1 = i1; this.
I2 = i2; } @Override public void paintIcon(Component c, Graphics g, int x, int y) { i1. PaintIcon(c, g, x, y + (getIconHeight() - i1.getIconHeight()) / 2); i2. PaintIcon(c, g, x + ICONSPACING + i1.getIconWidth(), y + (getIconHeight() - i2.getIconHeight()) / 2); } @Override public int getIconWidth() { return i1.getIconWidth() + ICONSPACING + i2.getIconWidth(); } @Override public int getIconHeight() { return Math.
Max(i1.getIconHeight(), i2.getIconHeight()); } }.
The easiest way is to combine the two icons into one. You can do this either manually (if you have only few combinations) or write an Icon implementation on your own. You can e.g. Align the two icons side-by-side with the following implementation: import java.awt.
Component; import java.awt. Graphics; import javax.swing. Icon; public class DoubleIcon implements Icon { private static final int ICONSPACING = 4; private final Icon i1; private final Icon i2; public DoubleIcon(Icon i1, Icon i2) { this.
I1 = i1; this. I2 = i2; } @Override public void paintIcon(Component c, Graphics g, int x, int y) { i1. PaintIcon(c, g, x, y + (getIconHeight() - i1.getIconHeight()) / 2); i2.
PaintIcon(c, g, x + ICONSPACING + i1.getIconWidth(), y + (getIconHeight() - i2.getIconHeight()) / 2); } @Override public int getIconWidth() { return i1.getIconWidth() + ICONSPACING + i2.getIconWidth(); } @Override public int getIconHeight() { return Math. Max(i1.getIconHeight(), i2.getIconHeight()); } }.
1 Implementing Icon is very convenient for this; here's a related example. – trashgod May 30 at 16:12 @trashgod I just added a specific example the second you wrote your comment. Nevertheless, thank you for the link.
– Howard May 30 at 16:15 Thank You , it was usefull . Thanks alot ;) – SpiXel May 30 at 16:21 @mre recently suggested another good approach using AlphaComposite, which may be easily combined with this suggestion. See also this example utility.
– trashgod May 30 at 16:25 @Howard : what is ICONSPACING supposed to do here? – SpiXel May 30 at 16:26.
You'll need to combine the images before you set the button icon. How you do that depends upon how you want to composite them. Do you want one on top of the other, or do you want them side by side?
Either way, you'll need to do something like this: BufferedImage groundImage = ImageIO. Read(new File("ground. Png"); BufferedImage tankImage = ImageIO.
Read(new File("tank. Png")); Graphics2 g2 = groundImage.createGraphics(); g2. DrawImage(x, y, tankImage); Then groundImage will have tankImage drawn on top of it starting at coordinate (x, y).
At that point you can set the button icon to groundImage. (caveat: I just answered this on my iPad, so the code might nit be completely correct).
Wow it took me a long time to answer. Howard's answer is better. – Rob Heiser May 30 at 16:49.
Compound Icon gives you more flexibility on how the Icons are painted.
While I want the both images to be visible - Stack Overflow.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.