Swing Painting Problems

M

matt

I currently have an application that uses JFrames and the javax.swing
library for its GUI. I am trying to create a shopping cart where there
is a Basic and Expanded setting. The Basic Setting simply tells them
the cost of several different items and they are able to click an
Expand button that will show them more details. The way I am
accomplishing this is having 2 separate JPanels (basic and expanded)
and then when the user clicks the expand button i remove the basic
panel and then add the expanded panel in its place. This works except
when it happens the screen remains blank until i minimize and then
restore the program (I can also resize it) for the changes to appear.
I am wondering how to draw the changes to the screen. I think it has
something to do with the repaint() method???
For Reference: I am using a TableLayout class I found on Google as my
LayoutManager

Thanks,
Matt
 
A

Andrew Thompson

I currently have an application that uses JFrames ...
..having 2 separate JPanels (basic and expanded)
and then when the user clicks the expand button i remove the basic
panel and then add the expanded panel in its place.

Sounds like a job well suited to using a CardLayout.
..This works except
when it happens the screen remains blank until i minimize and then
restore the program (I can also resize it) for the changes to appear.
I am wondering how to draw the changes to the screen.

A call validate() will probably do the trick, but..*
..I think it has
something to do with the repaint() method???

Please fix that sticky '?' key.
What happened when you called repaint()?
For Reference: I am using a TableLayout class I found on Google as my
LayoutManager

* ..if not, you might need to post an SSCCE
that demonstrates the problem. Note that
to be an SSCCE, you will need to show the
problem in code that uses only classes of
the J2SE - so that TableLayout will have
to go.

Andrew T.
 
M

matt

Sounds like a job well suited to using a CardLayout.


A call validate() will probably do the trick, but..*


Please fix that sticky '?' key.
What happened when you called repaint()?


* ..if not, you might need to post an SSCCE
that demonstrates the problem. Note that
to be an SSCCE, you will need to show the
problem in code that uses only classes of
the J2SE - so that TableLayout will have
to go.

Andrew T.

Validate solved the problem. Thanks Andrew. I'd been wondering about
this problem for a long time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top