Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JFrame won't repaint...

 
Matthew Alesi
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This seems like an elementary issue, but it's tarnishing my application. When my GUI first shows, it's a toolbar with an empty JScrollPane below it, and you're supposed to cllick Open in the toolbar, and then stuff shows up below. But when I set up the stuff below and call setVisible(true) on the scrollpane to display all the contents, nothing shows up. The only way to make it display is to resize the frame.

Nonetheless, whenever I make any subsequent changes, the GUI updates itself properly.

Why is this happening, and how can I get my GUI to repaint for sure without an ugly (unnecessary) resize?

This is due soon. Thanks everybody!
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you add components to the scrollPane you will need (after adding)
scrollPane.revalidate();
scrollPane.repaint();//sometimes required, sometimes not

if this is not the problem, post a sample program that displays the behavior.

(be a good idea for you to delete your duplicate post)
 
Matthew Alesi
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a small program that replicates the problem. You have a button on the top that sets the text of a label on a panel within the scroll pane. However, the window doesn't update.



I hope this helps!
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
seems to work OK with this change

//scrollPane.revalidate();
//scrollPane.repaint();
frame.validate();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic