Try creating a minimal code fragment and post it here, or better yet on
http://stackoverflow.com/.
Here's a sample of one approach:
Code:
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Temp extends JFrame {
static int WIDTH = 400;
static int HEIGHT = 300;
int buttonCount = 1;
public Temp() {
setLayout(new FlowLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addButton();
setSize(WIDTH, HEIGHT);
}
public void addButton() {
JButton b = new JButton("Button " + buttonCount++);
b.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
addButton();
}
});
add(b);
revalidate();
}
public static void main(String[] args) {
Temp t = new Temp();
t.setVisible(true);
}
}