我有一个设置文件夹目录的重命名工具,但是我创建了一些 JCheckBox,我希望他们能够根据选择的目录更改目录。
她是复选框的动作侦听器,它编辑 txt 字段,使其在程序上看起来正确,但实际上并没有更改目录。
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
这是命令目录设置的代码
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
如何修改此代码以实际更改目录?
if(cbxBlackBerry.isSelected())
txtDirectory.setText("\\RSASoftToken\\blackberry");
else{
txtDirectory.setText("");