• Post Reply Bookmark Topic Watch Topic
  • New Topic

How can I get my delete button to actually delete the name and the checkbox next to it?

 
Pyuntae Chan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to get my program for user to check a checkbox with a name next to it and then be able to delete the whole row (from arrayList) when pressing the delete button. My program will look something like this:


The problem is I have no idea how to invoke the components so that it takes out the names from the arraylist. Everytime I try to put nameCheckBox under the DeleteButtonListener it says they can't find the symbol and I even tried to put the JCheckBox nameCheckBox = new JCheckBox(); as a field and it does not work.

Here's my code:



Here's my AddUsers Class:

 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In pseudo code
1) Use the getComponentCount() method available in the namePanel to see how many children are available at runtime
2) Iterate over all children to obtain a reference to one child at a time
3) Check if the child is an instanceof JCheckBox
4) If yes, confirm the check box child is ticked (checked)
5) If yes invoke namePanel#remove(child)
6) When you are done removing all eligible children, call revalidate(); and repaint(); (in that order) on the name panel to ensure the UI is refreshed properly
 
Pyuntae Chan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did what you said but now it's just deleting everything when I hit Delete button:

 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


You forgot the step where you remove the checkbox ONLY if it is checked.
4) If yes, confirm the check box child is ticked (checked)
5) If yes invoke namePanel#remove(child)
 
Pyuntae Chan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought that's what I did? Even if i do this it doesn't work either.

 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Pyuntae Chan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:


omg. Thank you so much. you do not know how long i've struggled trying to get this to work.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are welcome.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!