I have a rename tool that sets a folder directory, however I created some JCheckBox and I want them to be able to change the directory depending on which is selected.
Her is the action listener for the checkbox, it edits the txt field so it looks right on the program but does not actually change the directory.
cbxBlackBerry = new JCheckBox("BlackBerry");
cbxBlackBerry.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
if(cbxBlackBerry.isSelected())
txtPrefix.setText("x-rimdevice_");
else{
txtPrefix.setText("");
}
if(cbxBlackBerry.isSelected())
txtDirectory.setText("\\RSASoftToken\\blackberry");
else{
txtDirectory.setText("");
}
}
}
); //close addActionListener
this is the code that commands the directory setting
private boolean chooseDirectory(){
/* Choose the file Directory
* this will ensure that the class variable directory get the value
* only when a directory is chosen, then the button Ok will be enabled
*/
JFileChooser fc = new JFileChooser();
fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
fc.setAcceptAllFileFilterUsed(false);
int returnval = fc.showOpenDialog(this);
if(returnval == JFileChooser.APPROVE_OPTION){
directory = fc.getSelectedFile();
btnOk.setEnabled(true);
return true;
}
return false;
}// end chooseDirectory
How do I modify this code to actually change the directory?
if(cbxBlackBerry.isSelected())
txtDirectory.setText("\\RSASoftToken\\blackberry");
else{
txtDirectory.setText("");
You need a method like this:
and where you have code that sets the directory JTextField, call this method instead. So for instance, instead of
Do something like:
And at the top of the class, have a constant if need be: