Peter Taucher wrote:So, how do you create buttons dynamically? Is there by any chance a collection of buttons? No crystal ball here. There's no difference in defining one button or a bunch of buttons, so you'd better provide a more thourough description of your 'problem'.
We got a topic around here on danymic menu items ... maybe you want to look it up (it's not that different, because menu items and buttons are handled very similar):
https://coderanch.com/t/498424/GUI/java/applying-actionlistener-dynamic-submenu
I had a JFrame which contains one jbutton and a jpanel. then i'm adding jbuttons like this..
here pan--> jpanel
//
//
int number = Integer.parseInt(JOptionPane.showInputDialog("Enter the number:"));
pan.removeAll();
for(int i=0;i<number;i++){
pan.setLayout(new GridLayout(4,2));
button = new JButton("Button"+i);
button.setName("Button"+i);
pan.add(button);
pan.revalidate();
}
later i want to access those buttons and get their names by click event..>