• Post Reply Bookmark Topic Watch Topic
  • New Topic

Swing Clear Fields and CheckBoxes

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an internal Frame that has several TextFields and CheckBoxes, and I would like to be able to clear all the data with the push of a button. Is there anyway to do that without removing and then adding each component?
 
Chris Shepherd
Ranch Hand
Posts: 286
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
just keep references to these clearing components, and when you push your button, set the text field values to "" and set the checkboxes to false.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I undertand that, but how do I get the window to refresh itsleft so that everything is cleared?
 
Tighe Fagan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try a call to validate();
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't seem to find that method on java.sun. Can you point me to a link of the API that explains that, or explain what validate() does?
 
Tighe Fagan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Go here and look in the Container class:
http://java.sun.com/j2se/1.3/docs/api/index.html
I would recommend downloading these docs:
http://java.sun.com/j2se/1.3/docs.html
I use them all day for quick reference.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, if I understand, which I rarely do at first. If I have a checkbox called: GenderCheck, RaceCheck, etc, I can clear all those with one validate() method on the container? What if my container is a JTabbedPane? I can't seem to get it to work. I have JTabbedPane topPane = new JTabbedPane()
Then when I click a button I have topPane.validate()
Is that right or wrong?
 
Tighe Fagan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That should work, I just tried it with
a JPanel and a JFrame and both times it
repainted the screen correctly. I'll try it
with a JTabbedPane and let you know.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, I would appreciate it. I have had some problems with JTabbedPanes repainting correctly on some other functions as well. And the same functions worked with a JFrame. So it must be something in the JTabbedPane. But thanks for your help and let me know.
 
Tighe Fagan
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:
On any Jcomponent(e.g. your JTabbedPane):
myJTabbedPane.getTopLevelAncestor().validate()
Ensure via System.out.println that the getTopMostAncestor()
returns your top level JFrame(As a sanity check).
This should redraw the entire app frame and your
TabbedPane.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!