Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Refresh problems?

 
Tim Manchester
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy, for my own gratification, I'm working on a project to create a GUI to display calendar information. I'm using NetBeans 5.0 beta 2 which has a good visual tool for laying out a UI. That said, here is what I have:
A jFrame with 3 vertically stacked jPanels.

The top jPanel contains a button (decrase month), a label (month year display) and another button (increase month).

The middle jPanel contains 7 labels for each day of the week.

The bottom jPanel contains 42 buttons laid out in 6 rows of 7 columns.

I have a method that configures the components by looking at the current month and hiding buttons that do not correspond to days on the calendar for that month and setting the text on the buttons to correspond to the correct day.

The problem that I have is that some months have 6 weeks and some done (most don't). So I create two additional methods, cropDialog and expandDialog that are called when we need to resize the jFrame and bottom jPanel to accomodate the 6th week.

cropDialog is working great. expandDialog seems to resize the jFrame and jPanel correctly (I'm using log4j console output to track the before and after Dimension objects of the jFrame and jPanel) BUT when I get to April 2006 (the first 6 week month), the only button on the 6th week is cut in half with only the top half visible. My debug output indicates that the jFrame and jPanel are resized correctly.

What sort of problems should I be looking for?

In addition, I'm not sure if it mattered but the method cropDialog first shrinks the jPanel before the jFrame and expandDialog expands the jFrame before the jPanel. Does order matter?

Regards,

- Tim Manchester
[ November 28, 2005: Message edited by: Tim Manchester ]
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
expandDialog expands the jFrame before the jPanel. Does order matter?
It might. You can get the middle jPanel size refreshed by calling either the JComponent method revalidate or the Container/Component method validate on it after making the desired changes to its child components. Once this is done you can accurately resize the parent JFrame by calling pack on it.
 
Tim Manchester
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using the validate method did the trick. Apparently it works differently from repaint. Thanks for the suggestion.

Regards,

- Tim
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic