• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do I clear graphics from a JFrame?

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to move some text over a clear background, but the old frames are not getting removed.

This is how it looks like:


I tried to remove all components from the JFrame, tried re-creating the frame(causes flicker), tried doing the clearRect method, but it fills it with solid color, doesnt work with a clear one.

How would I go about doing that?
 
Rancher
Posts: 1171
18
IntelliJ IDE Hibernate Firefox Browser MySQL Database Spring Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not so familiar with swing, JavaFx all the way .
Anyway, from the screenshot you posted we can't tell that mutch.
You said you tried to remove the components, if you remove the components how is it possible that it's still there.
On what dit you try to set the color, in this case you would have to set the color of the text not of the component the text is in, fyi the color would be transparrent.
And otherwise there still opacity. But I don't think that's the way to go, I wouldn't hide it, I would try to remove it
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

I am afraid I can't read that screenshot, and I have forgotten where I put my dark gasses to cope with all the text colours
Why are you removing components? Really, once you have a GUI visible, you should probably neither add nor remove components, otherwise you will get a very peculiar appearance.
Are you really painting something on a frame? That isn't the right way to do it. Paint on a panel, and override its paintComponent() method. Three things to notice:
  • 1: It has protected access.
  • 2: You never call it yourself.
  • 3: Line 10 clears the painting before it becomes visible, and clears the old painting whenever the display changes.
  • This is one of the few instances where I think it is a good idea to extend a display class. It is probably a good idea to make that class a private inner class, or you can create it as anonymous class.
     
    Campbell Ritchie
    Marshal
    Posts: 79177
    377
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    Don't use Thread#sleep. Use a timer instead.
     
    reply
      Bookmark Topic Watch Topic
    • New Topic