gpt4 book ai didi

java - JFileChooser 远程 View

转载 作者:行者123 更新时间:2023-11-29 08:03:31 24 4
gpt4 key购买 nike

我一直在实现一个 JFileChooser 作为远程文件系统的 View 。当从 FileSystemView 调用 getFiles() 时,我将请求发送到包含目录位置数据的远程系统。

然后我异步接收包含我正在浏览的目录中所有文件的返回数据包,之后我将文件设置为更新 View (以便下次调用 getFiles() 时它将返回接收到的文件数组),但问题是我不知道如何更新 JFileChoosers View 。

我试过了

fileChooser.updateUI();

但它抛出以下异常:

Exception in thread "pool-1-thread-31" java.lang.NullPointerException
at com.sun.java.swing.plaf.windows.WindowsFileChooserUI.setDirectorySelected(Unknown Source)
at javax.swing.plaf.basic.BasicFileChooserUI$Handler.valueChanged(Unknown Source)
at javax.swing.JList.fireSelectionValueChanged(Unknown Source)
at javax.swing.JList$ListSelectionHandler.valueChanged(Unknown Source)
at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
at javax.swing.DefaultListSelectionModel.moveLeadSelectionIndex(Unknown Source)
at sun.swing.FilePane.clearSelection(Unknown Source)
at sun.swing.FilePane.doFilterChanged(Unknown Source)
at sun.swing.FilePane.propertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.fire(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.awt.Component.firePropertyChange(Unknown Source)
at javax.swing.JFileChooser.setFileFilter(Unknown Source)
at javax.swing.JFileChooser.addChoosableFileFilter(Unknown Source)
at javax.swing.JFileChooser.updateUI(Unknown Source)
at com.ruuhkis.remoteserver.ui.RemoteView.updateFiles(RemoteView.java:252)
at com.ruuhkis.remoteserver.ui.RemoteApplication.onFileListReceived(RemoteApplication.java:122)
at com.ruuhkis.remoteserver.packets.impl.FileListPacket.handlePacket(FileListPacket.java:32)
at com.ruuhkis.remoteserver.packets.PacketHandler$1.run(PacketHandler.java:57)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

当我在目录中并且我知道它已收到新文件列表并且我按 f5 时它会显示它刚加载的新文件,我怎样才能做到不必按 f5?此外,通过按 f5,它会导致系统重新加载目录的预先存在的数据。

当前代码基本上是:

    view = new FileSystemView() {

int c;

@Override
public File[] getFiles(File dir, boolean useFileHiding) {

if(!auto) {
PacketBuilder builder = new PacketBuilder(OpCodes.FILE_LIST_REQUEST_PACKET.getOpCode());
root = dir.getAbsolutePath();
builder.writeString(dir.getAbsolutePath());
builder.write(RemoteView.this.remote.getChannel());
}
auto = false;



if(dirContent == null)
return new File[]{new File((c++) + ".txt")};
else
return dirContent;
}

@Override
public Boolean isTraversable(File arg0) {
return true;
}

@Override
public File createNewFolder(File arg0) throws IOException {
// TODO Auto-generated method stub
return null;
}
};

c 基本上只是为了测试所以我可以看看系统是否得到刷新

当我收到文件列表时,我会这样做:

public void updateFiles(String list) {
String[] parts = list.split("" + ((char)10));
File[] files = new File[parts.length];

for(int i = 0 ; i < parts.length; i++) {
files[i] = new File(root + File.separatorChar + parts[i]);

}



dirContent = files;

fileChooser.setCurrentDirectory(new File(root));

fileChooser.updateUI();

auto = true;

}

最佳答案

关于java - JFileChooser 远程 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12914209/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com