Swing: How do I add buttons to specific spots on a panel?
Hi,
I currently have a 500 * 500 image which is the background of a JPanel (So I suppose I have a 500 * 500 JPanel, basically).
I would like to be able to place (20*20) buttons on various places of this image - for instance, add button1 at position (200, 420), then button2 at position (100, 480), etc. Is there a straight forward way to do this?
Thanks.
[381 byte] By [
dodge] at [2007-11-11 7:54:47]

# 1 Re: Swing: How do I add buttons to specific spots on a panel?
import java.applet.*;
import java.awt.*;
public class DoButton extends Applet {
Button b1;
public void init() {
b1 = new Button("Press Me");
add(b1);
}
}
Try this it might work.
# 2 Re: Swing: How do I add buttons to specific spots on a panel?
import java.applet.*;
import java.awt.*;
public class DoButton extends Applet {
Button b1;
public void init() {
b1 = new Button("Press Me");
add(b1);
}
}
Try this it might work.
No. That just adds it to the container. You need to set the location using the setLocation(int, int) or setLocation(Point) method.
Good luck!
destin at 2007-11-11 22:38:03 >
