[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

My JFrame does not refresh!!

Posted on 2004-09-12
12
Medium Priority
?
534 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 240 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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.
Suggested Courses

649 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