This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

repainting JFrame  RSS feed

 
Petar Thomas
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is simple. I added a JButton in ContentPane, with ActionListener and it's method actionPerformed(ActionEvent e), in which there is a code for generating a new button every time someone pushes a button. The generated button should appear in a frame, but it does only if I resize window, or if i put pack() method, but problem with pack() for me is that it resizes the frame, which I don't want to be necessarily so. How can I redraw the frame with some new contents inside, like a new button, but that the size of the frame stays the same?

Thank you in advance

 
Rob Camick
Ranch Hand
Posts: 2787
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you add (or remove) a component from a visible GUI you need to tell the layout manager to layout the components again. The basic code is:

 
Petar Thomas
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!