好吧,我有一個返回路徑的方法,通過JFileChooser,我想將該路徑保存在一個變量中,然后修改一個File. JFrame但是當我用 line:調用按鈕中的方法時 tf.guardarTareasHash(operator.obtenerTabla(), "modificar", tf.path());,我意識到我FileDialog再次打開以選擇文件。本來想用tf.path()send之類的參數,但沒想到會再次打開JFileChooser。如果程序將保存新文件或修改,該行發送一個和修飾符是我在條件中發送用于檢查operator.obtenerTabla()的Hashtable一個。String public String path(){
JFileChooser jfc = new JFileChooser();
jfc.setCurrentDirectory(new
File("C:\\Users\\ARCANET\\Documents\\NetBeansProjects\\hash\\tareas"));
jfc.showOpenDialog(jfc);
String ruta = jfc.getSelectedFile().getAbsolutePath();
return ruta;}? 無論如何都可以在不打開文件的情況下存儲所選文件的路徑OpenDialog?我想static為它做一個變量。
1 回答

偶然的你
TA貢獻1841條經驗 獲得超3個贊
如果我理解正確你想要
tf.guardarTareasHash(operator.obtenerTabla(), "modificar", tf.path());
不要再次打開文件對話框。在這種情況下,您需要在第一次調用路徑方法時存儲它的結果,然后將結果作為第三個參數傳遞,而不是再次調用路徑方法。
class MyClass {
String myPath = null;
...
// call the path method which opens the file dialog
myPath = path();
...
// use the saved result
tf.guardarTareasHash(operator.obtenerTabla(), "modificar", myPath);
}
myPath如果未初始化,您仍然必須執行檢查(例如用戶取消文件對話框)
添加回答
舉報
0/150
提交
取消