• Post Reply Bookmark Topic Watch Topic
  • New Topic

Dynamically adding buttons in jframe  RSS feed

 
tajinder pal singh
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,


Am trying to add buttons dynamically in a new Jpanel on click of a button.
i am getting new Jpanel but not able to see the buttons.






prepareHandsForGuiCode is





Am i skipping something ?
PLease advice . THanks
 
Rob Camick
Ranch Hand
Posts: 2788
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you add components to a visible GUI the basic code is:



So in in your case you would add all the components to the panel in the loop and then after the loop is finished executing you would do the revalidate() and repaint().
 
Campbell Ritchie
Sheriff
Posts: 55366
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But why do you want to add things? The display will gradually become more and more crowded. If you want buttons to appear and disappear find out about card layout.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!