Results 1 to 4 of 4
Thread: Removing Items In a GUI
- 08-01-2010, 04:21 AM #1
Member
- Join Date
- Mar 2010
- Location
- Hilton Head, SC
- Posts
- 34
- Rep Power
- 0
Removing Items In a GUI
So I know that if you remove something, you would remove('obj'); revalidate(); repaint();
What I'm doing wrong is this:
Now this doesn't work. If I do something likeJava Code:JButton button = new JButton("Remove Me"); JButton.setBounds(200, 200, 100, 20); // Layout set to null, this is required add(button); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { remove(this); revalidate(); repaint(); } });
and useJava Code:private JButton button;
This works fine. Can you explain to me why the remove(this); doesn't work. I know I'm not using this properly, I just don't know exactly what about it is wrong and how I can get it to work correctly.Java Code:remove(button);
-
Since "this" refers to the class you are currently in when you are calling
you are trying to remove the ActionListener anonymous inner class, not the JButton.Java Code:remove(this)
To remove the JButton, you must call
Java Code:remove((JButton)event.getSource());
edit: please note that you never replied to answer given to you in your previous thread. Since none of us are paid to help out here, our payment is your thanks, and we always appreciate replies to our posts, even if it's nothing more than a simple acknowledgment that you've read our posts. I'm sure you understand why this is important. Thanks for your cooperation.Last edited by Fubarable; 08-01-2010 at 04:58 AM.
- 08-01-2010, 05:35 PM #3
Member
- Join Date
- Mar 2010
- Location
- Hilton Head, SC
- Posts
- 34
- Rep Power
- 0
Alright, that worked fine. I think my problem was that I was thinking jQuery and not Java.
-
Similar Threads
-
Adding \ removing items from Jlist
By Desperado in forum AWT / SwingReplies: 10Last Post: 12-17-2009, 12:48 PM -
Removing Buttons?
By Mass Zero in forum Java AppletsReplies: 10Last Post: 10-28-2009, 03:16 PM -
Removing Indexes
By gilbertsavier in forum JDBCReplies: 0Last Post: 07-17-2009, 07:23 AM -
trouble in removing a value
By jacline in forum New To JavaReplies: 5Last Post: 03-20-2009, 05:56 PM -
removing reference
By ajith_raj in forum Advanced JavaReplies: 4Last Post: 02-12-2009, 11:46 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks