我创建了一个带有 3 个选项卡的 JTabbedPane。
当我切换到不同的选项卡时,stateChang 不响应单击。
当我将调试标记放在 public void stateChanged(ChangeEvent e) { }
中的代码中时,单击后没有看到任何效果。
原因是什么以及如何解决?
public class TabbedPanChangeListener implements ChangeListener {
ConfigToolScannersPanel panel;
List<String> artikels = GenericsUtil.makeList();
public TabbedPanChangeListener(ConfigToolScannersPanel configToolScannersPanel) {
this.panel = configToolScannersPanel;
}
public void stateChanged(ChangeEvent e) {
WebTabbedPane sourceTabbedPane = (WebTabbedPane) e.getSource();
int index = sourceTabbedPane.getSelectedIndex();
String titel = sourceTabbedPane.getTitleAt(index);
File dirconfig = new File("C:\\tmp\\config");
File dirPictures = new File("C:\\tmp\\Pictures");
File diraxi = new File("C:\\tmp\\");
File artikels = new File("C:\\tmp\\artikels.csv");
if (dirconfig.exists()) {
if (titel.equalsIgnoreCase("ftp")) {
panel.updateUI();
} else if (titel.equalsIgnoreCase("Picture")) {
setSelectedFileToNull();
BorderLayout layout = (BorderLayout) panel.pictureTabPanel.getLayout();
panel.pictureTabPanel.remove(layout.getLayoutComponent(BorderLayout.WEST));
panel.pictureTabPanel.add(FileList.getGui(dirPictures.listFiles(), true, panel), BorderLayout.WEST);
panel.pictureTabPanel.remove(layout.getLayoutComponent(BorderLayout.NORTH));
panel.pictureTabPanel.add(FileList.getGui(diraxi.listFiles(), false, panel), BorderLayout.NORTH);
panel.pictureTabPanel.remove(layout.getLayoutComponent(BorderLayout.CENTER));
// *** Add and remove from tool bar ***
visibaleInvisibale(false);
panel.btnDelete.setVisible(true);
panel.btnDelete.setAction(new DeletePictureAction(panel));
panel.btnAdd.setVisible(true);
panel.btnAdd.setAction(new AddPictureAction(panel));
panel.updateUI();
} else if (titel.equalsIgnoreCase("dienst")) {
}
}
}
最佳答案
您在代码中调用了这一行吗?
tabbedPane.addChangeListener(new TabbedPanChangeListener(configToolScannersPanel));
关于java - 为什么 JTabbedPane 不响应单击选项卡?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10010052/