Solved

My JFrame does not refresh!!

Posted on 2004-09-12
12
532 Views
Last Modified: 2012-08-14
Hi guys

I currently have problems refreshing my JFrame. It gets blurred when I move some other windows over it.

mainFrame.getContentPane().add("The object I want to add);
((JComponent)mainFrame.getContentPane()).validate();
mainFrame.getContentPane().repaint();

I wonder whether it is correct.
When I set super.paint(), my object will refresh BUT the second object which I draw using the same method as above will not be shown.

What can i do?
I tried using paintComponent and repaint but it is no use.

Please help!
0
Comment
Question by:ricteo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 24

Expert Comment

by:sciuriware
ID: 12038325
How about mainFrame.setVisible(true);

;JOOP!
0
 

Author Comment

by:ricteo
ID: 12038408
Cannot work lah. I thought setVisible is just to make the JFrame visible?
0
 
LVL 24

Accepted Solution

by:
sciuriware earned 60 total points
ID: 12039274
It also boosts display when components have been added.
B.t.w. I always fill my mainframes with JPanels etc. that I may fill later with components.
In situations where I change a lot to a JPanel I practise:

   /**
    * Destroys the display after completion.
    */
   public void destroyComponent()
   {
      SwingUtilities.invokeLater
      (
         new Runnable()
         {
           public void run()
           {
              paneXyz.remove(thatComponent);
              paneXyz.revalidate();
              paneXyz.repaint();
           }
         }
      );
   }

It's also possible to make your class a Thread extension to have more access to references.
This construct is only needed when the action is in the display thread: from a button or timer.

;JOOP!
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ricteo
ID: 12045473
Hi

Is the paneXyz the Jframe?

Thanks
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12052775
paneXyz (is a pane!) is the JPanel where you once added the component:

        paneXyz.add(thatComponent); ---> paneXyz.remove(thatComponent);

;JOOP!
0
 

Author Comment

by:ricteo
ID: 12053401
Hi

But I am using getContentPane().add(thatComponent);

How?
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12054763
Better place separate components in a JPanel that, if it's alone, sits in BorderLayout.CENTER of the contentpane.

;JOOP!
0
 

Author Comment

by:ricteo
ID: 12055850
What do you mean?
Do you mean it could be because i did not specify which part of the Jpanel  it should display in?


Thanks
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12061756
No, you should not place components directly into the contents pane.
;JOOP!
0
 

Author Comment

by:ricteo
ID: 12065821
Oh, Do you mean that I should have a JPanel which I should put my components into and then place the JPanel into the content pane?

Thanks
0
 
LVL 24

Expert Comment

by:sciuriware
ID: 12067539
Yes that's what I said all the time.
And most of the examples in books and tutorials work that way.
;JOOP!
0
 

Author Comment

by:ricteo
ID: 12072030
Ok. I go and try it out. I will give you your points if it works!
Thanks
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question