Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

jPanel4.removeAll() is not working suddenly without showing any errors

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My project is a pos system and it's home page is a jfame.When click buttons for new a invoice  form is loading to a jpanel (jpanel).

 
after finishing bill i'm removing jpanel content and load a new form.That is my main process.

So my problem is after I added 14 or 15 bills suddenly stuck the invoice form without any errors.I check the code it is stopping @.After clicking new invoice on my main frame it's working again. Please help me to solve this problem.

[b]
 
Rancher
Posts: 3191
29
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use the updateUI() method. That is used internally by Swing for a LAF change. You are not changing the LAF.

The basic logic for adding/removing components from a panel is:



There is no need for the setVisible(). Swing components are visible by default.

There is no need to reset the layout manager for the panel. Removing the components does not change the layout manager.
 
Marshal
Posts: 69783
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and welcome to the Ranch
 
Prashad Nuwanpriya
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for helping me. But the problem not solved yet. I identified something my program.it is increasing memory quickly and doesn't clear memory either remove the jpanel or close jframe. How can I control it. I have used .
 
Rob Camick
Rancher
Posts: 3191
29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We can't tell what you are doing wrong based on the code posted.

Post a SSCCE the demonstrates the problem.

So all you need is a JFrame with a panel and some components add to the BorderLayout.CENTER.

Then you create a button that will replace the panel and its components and add this button to the BorderLayout.PAGE_END.

This will demonstrate the concept of replacing panels.

If it works then you apply the knowledge to your real program.

If it doesn't work then you have simple code to post in the forum.
 
Campbell Ritchie
Marshal
Posts: 69783
277
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Prashad Nuwanpriya wrote:. . . . I have used .

That won't make any difference. If you run out of memory, it is because objects are remaining reachable which shouldn't. You haven't shown us any succh code, so we have no way to know any explanation for the memory leak.
 
Ranch Hand
Posts: 218
5
MS IE Notepad Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also: make sure any modifying of swing components is only done from eventdispatchthread.
 
Time is the best teacher, but unfortunately, it kills all of its students - Robin Williams. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic