What I'm having problems with is that I have a list of 10 files in a JList. On a JButton, I have "attached file(s) 0." What I'm trying to achieve is when a user clicks on a file in the JList, the variable fileCount (represents the '0') will increment. Here is the code:
@Override
public void mouseClicked(MouseEvent arg0) {
int idx = list_fileListing.getSelectedIndex();
String eFiles[] = ig.getListOfFiles();
if(idx == list_fileListing.getSelectedIndex()){
fileCount++;
}
}
Basically, if a file is selected, increment fileCount. Any suggestions as to how to accomplish this?
The JButton
class has a setText()
method like many of the other Swing component classes. You can use this method to overwrite the text that is currently on the JButton
.
ex:
if(idx == list_fileListing.getSelectedIndex())
{
fileCount++;
yourButtonName.setText("attached file(s) " + fileCount);
}
hope this helps.
getSelectedIndices()
method from the JList class, it should return an array of all the selected indexes. http://docs.oracle.com/javase/7/docs/api/javax/swing/JList.html#getSelectedIndices( - Hunter McMillen 2012-04-04 01:36