我想檢測選項卡何時發生變化並檢索選定的索引。我所能找到的所有例子都顯得過時,並且我無法成功實現它們。ChangeListener不按預期方式工作JTabbedPane
它強制我將changeListener轉換爲javax.swing.event.ChangeListener,但同時不讓我編譯它。我哪裏錯了?
ChangeListener changeListener = new ChangeListener() {
public void stateChanged(ChangeEvent e) {
JTabbedPane sourceTabbedPane = (JTabbedPane) e.getSource();
int index = sourceTabbedPane.getSelectedIndex();
System.out.println("Tab changed to: " + index);
}
@Override
public void changed(ObservableValue arg0, Object arg1, Object arg2) {
// TODO Auto-generated method stub
}
};
tabbedPane.addChangeListener((javax.swing.event.ChangeListener) changeListener);