为什么JTabbedPane没有响应单击选项卡?

时间:2012-04-04 11:20:30

标签: java swing jtabbedpane

我创建了一个带有3个标签的JTabbedPane。 当我切换到不同的选项卡时,stateChang没有响应click。 当我将调试标记放在side public 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")) {

        } 
    }
}

1 个答案:

答案 0 :(得分:2)

您是否在代码中调用了此行?

tabbedPane.addChangeListener(new TabbedPanChangeListener(configToolScannersPanel));