我遇到如下情況:帶有多個選項卡的GUI。每個選項卡都顯示我的主目錄中特定目錄中的文件內容。其中一些目錄存在於GUI創建時,其他目錄不存在。在通過FTP選項卡之一中,我得到一些文件並將其添加到主目錄。將新文件添加到目錄時更新JTabbedPane
注:我使用的是Java 5的
如何讓每個標籤知道FTP又增加了一個新的文件屬於此選項卡的目錄?
public class ScannerPanel extends JPanel implements ChangeListener {
private void initGUI() {
setPreferredSize(new Dimension(700, 400));
JTabbedPane tabbedPane = new JTabbedPane();
tabbedPane.addTab("FTP", IconLib.ICON_16X16_DATA,new FtpTabPanel (this),"FTP");
tabbedPane.addTab("PCS", IconLib.ICON_16X16_THUM,new PcsTabPanel (this),"PCS");
tabbedPane.addTab("Car", IconLib.ICON_16X16_PAPE,new CarTabPanel (this),"Car");
tabbedPane.addTab("Pic", IconLib.ICON_16X16_RETI,new PicTabPanel (this),"Pic");
tabbedPane.addChangeListener(this);
add(tabbedPane);
}
public void stateChanged(ChangeEvent e) {
//detect new file has been added to directory
// update the content of tab
}
}
由於您需要Java 6,因此可能是[WatchService for Java 6]的副本(http://stackoverflow.com/questions/7968488/watchservice-for-java-6)。 – trashgod