FocusListener not firing

here i have attached a componentListener to this.  but i have also tried attaching it to all panels in this class -> i would expect this to be fired when a component becomes visible on screen, but it never gets fired!
 WHY NOT!!

this.setLayout(new BorderLayout(gap, gap));
    this.add(toolBar, BorderLayout.NORTH);
    this.add(contents, BorderLayout.CENTER);
    this.addComponentListener(new ComponentListener()
    {
      public void componentShown(ComponentEvent e)
      {
        int i = 0;
        if(firstEntry)
        {
          splitPane.setDividerLocation(0.5);
          firstEntry = false;
        }
      }
      public void componentResized(ComponentEvent e)
      {
      }
      public void componentMoved(ComponentEvent e)
      {
      }
      public void componentHidden(ComponentEvent e)
      {
        int i = 0;
      }
    });
cathalmchaleAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
Possibly because the layout into which 'this' is placed has not rendered it
0
objectsCommented:
add some debug to verify that the listener is in fact not being called:

  public void componentShown(ComponentEvent e)
  {
     System.out.println("shown");
     ...
0
objectsCommented:
you'll also only get that event fired if you are calling setVisible().
Is this the case?
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

cathalmchaleAuthor Commented:
>>  you'll also only get that event fired if you are calling setVisible().
Is this the case?

no its not the case. i had another very similar example which selected the appropriate panel and component for focus when the application started up.  it worked nicely.
  in this example i just want to set the divider location to 0.5 - this can only be done when the component is visible because setting it to 0.5 before it is visible has absolutely no effect
0
objectsCommented:
can u post that example?
0
cathalmchaleAuthor Commented:
 // only for initial visuals and selections
    this.addComponentListener(new ComponentListener()
    {
      public void componentResized(ComponentEvent e)
      {
      }
      public void componentMoved(ComponentEvent e)
      {
      }
      public void componentHidden(ComponentEvent e)
      {
      }

      public void componentShown(ComponentEvent e)
      {
        Component comp = e.getComponent();
        getDockingManager().activateFrame(navigatorFrame.getKey());
        getDockingManager().setDefaultFocusComponent(navigatorFrame);
        navigatorFrame.firstTimeView();
        comp.removeComponentListener(this);
      }
    });

where this is simply extending JPanel, but this example works where as the other does not.  i guess the only difference being that this example is visual on start-up (the first thing u see), whereas the other jpanel is a tab which is not initially visible at startup
0
objectsCommented:
whats in the listener is not important, it is how it is made visible that determines whether the listener gets called.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
cathalmchaleAuthor Commented:
OK, I added a tab listener, when the tab is selected i call
thePanel.setVisible(true);
and the listener is called and it works nicely.

but how do i deal with the case where this tab is the first and initially visible tab - so the tabListener will not catch tab changed event??
0
objectsCommented:
how come you don't already know when it is being displayed?
0
cathalmchaleAuthor Commented:
>>  how come you don't already know when it is being displayed?
in 1 case they open a file-type where this panel is a different tab, but in another case its the first tab!
0
objectsCommented:
but doesn't your code open it, so you know that it is being displayed
0
cathalmchaleAuthor Commented:
of course
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.