Results 1 to 6 of 6
- 09-19-2012, 11:58 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 28
- Rep Power
- 0
Removing components from an array
I am trying to add and remove JTextFields in JPanel whenever a button is pressed. If the JPanel contains any of the JTextField array, that is msg, all the elements of msg should be removed before adding. The adding method works fine. now i want to remove elements. Can someone help me in doing it? I have to somehow search the elements in the JPanel and get its name and delete it.
Thanks in advance
Java Code:code for adding JTextField int n = 0; JTextField[] msg= new JTextField[n]; for(int i=0; i<n; i++){ msg[i] = new JTextField(); msgMnemonic[i] = new JTextField(); panel.add(msg[i]); }
- 09-20-2012, 03:17 AM #2
Re: Removing components from an array
The Container class has a method for removing components from the container. Have you tried using it?elements of msg should be removedIf you don't understand my response, don't ignore it, ask a question.
- 09-20-2012, 03:03 PM #3
Member
- Join Date
- Mar 2010
- Posts
- 28
- Rep Power
- 0
Re: Removing components from an array
- 09-20-2012, 03:50 PM #4
Re: Removing components from an array
That looks about right. Have you tried it? What happened?something like, panel.remove(msg[i])If you don't understand my response, don't ignore it, ask a question.
- 09-20-2012, 11:41 PM #5
Member
- Join Date
- Mar 2010
- Posts
- 28
- Rep Power
- 0
-
Re: Removing components from an array
Consider creating and posting an SSCCE that demonstrates your problem, that would allow us to test your code and modify it.
Similar Threads
-
After removing some components, frame's layout doesn't correct itself until resized.
By Vinx in forum AWT / SwingReplies: 8Last Post: 06-28-2012, 10:46 PM -
removing and adding SWING components
By Athlon* in forum AWT / SwingReplies: 1Last Post: 12-06-2011, 06:12 PM -
Removing characters in an array
By dru36 in forum New To JavaReplies: 6Last Post: 11-27-2011, 12:56 PM -
Adding and removing components from a GridBagLayout
By peterhabe in forum New To JavaReplies: 4Last Post: 09-19-2010, 10:13 PM -
Removing components from JPanel
By Echilon in forum New To JavaReplies: 0Last Post: 12-30-2007, 04:05 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks