2

I'd like to track the focus for all components in my Java application. I registered a method which works for most of the components, but it does not work for changing tabs. Here's the code:

FocusManager.getCurrentManager().addPropertyChangeListener(new PropertyChangeListener() {
  @Override
  public void propertyChange(PropertyChangeEvent evt) {
    System.out.println(evt.getPropertyName() + " " + evt.getNewValue());
  }
}

If I change a tab in a JTabbedPane, it will not cause a message to be printed. I suspect that this is due to the JTabbedPane focus not being changed (as clicking on a different tab may mean that it still belongs to the parent JTabbedPane).

Is there a workaround for this or does anyone know of a save method to track focus changes in Java that works also for tabs being changed?

Cheers, Max

Max
  • 79
  • 4

1 Answers1

1

You can add a ChangeListener to the tabbed pane to listen for changes in tabs.

camickr
  • 321,443
  • 19
  • 166
  • 288
  • I was looking for something that is more general for all components. – Max May 07 '11 at 03:41
  • A tab is NOT a component so there is no focus change to listen for. The same as each cell in a JTable is not a component. These components use Action to navigate around the component. – camickr May 07 '11 at 04:57