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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.