Howdy, quick question here.
I have a program that will draw 4 squares on the screen with a second smaller square (call this the icon) on 1 of the 4.
I can then drag the icon around and place it on another squares. So I can move it to anyplace I want on these squares. The problem is when I am dragging the icon around, it goes under some of the squares - which is not desired, but over some of them - which is desired.
I looked at the tutorials and it say to use an alpha composite with SRC (or SRC_OVER, too iirc). Here is my paintComponent method:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| public void paintComponent(Graphics g) { clear(g); Graphics2D g2d = (Graphics2D)g; g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER)); for(int i=0;i<idata.length;i++) { } g2d.draw(square); } |
When I run this code, no change happens. Sometimes the icon will go over, other times it will go under.
I have a feeling I am missing something here but I am not sure.
Thank you for any help.>