Solved

My JFrame does not refresh!!

Posted on 2004-09-12
12
524 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
  • 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
 

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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
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.

744 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now