e840. 监听JTabbedPane中选中卡片的改变
A tabbed pane fires a change event whenever the selected tab is changed either by the user or programmatically.
// Create the tabbed pane JTabbedPane pane = new JTabbedPane(); // Add tabs...; see e830 向JTabbedPane中加入一个卡片 // Register a change listener pane.addChangeListener(new ChangeListener() { // This method is called whenever the selected tab changes public void stateChanged(ChangeEvent evt) { JTabbedPane pane = (JTabbedPane)evt.getSource(); // Get current tab int sel = pane.getSelectedIndex(); } });
Related Examples |