Hi, I am trying to display checkbox(s), and text field(s) and a button based on the number of files in a Directory. For example I want 3 Checkboxes(with the lable of the file name) and 3 text boxes with a Button if there are 3 files in the directory.
I have achieved to do this by using the following code,
What I fail to know is adding a diferent actionlistener to every differerent component. I have added the action listener to the components, but they call the same action performed method. (I do know that ActionListener fires the ActionPerformed method, but I want every component to do something else)
Eventually I want to take the file name and the number of records from each file; and then to display in the text area.
Any help on adding a different action listener?
Randall Twede wrote:the other approach is to use one actionListener and a switch or if statement
The only concern here would be that in case a new condition comes up then one would have to edit the if statement, kind of fragile.
Andrew Geroge Alexander
Joined: Feb 14, 2012
Hmmm... I tried implementing the Anonymous inner class, i have some bit of a problem. Say if there are two files in the jList, so the loop runs for two times thus placing two checkboxes with their file names, if the user clicks one checkbox i am taking it in a string array.
The problem now i have is, If the user decides to deselect the file when he clicks it again, it still gets recorded.
I have obtained the output as in the attachment. So if i click the file it is stored in the msg array if it is deselected it still is again stored in the array.
Did you debug to see if the event listener method is being invoked when you uncheck the CheckBox? I am not sure which event handles the check/uncheck operations (ActionListener is one, but there should be few specific to check box component)
The problem might be that the JList component is not refreshed to reflect the new array or the changes in the array.
How are you managing the deleting of String/File name from the array?