Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

FocusListener not firing

Posted on 2004-11-12
13
Medium Priority
?
258 Views
Last Modified: 2010-03-31
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;
      }
    });
0
Comment
Question by:cathalmchale
  • 6
  • 5
12 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 12570271
Possibly because the layout into which 'this' is placed has not rendered it
0
 
LVL 92

Expert Comment

by:objects
ID: 12576075
add some debug to verify that the listener is in fact not being called:

  public void componentShown(ComponentEvent e)
  {
     System.out.println("shown");
     ...
0
 
LVL 92

Expert Comment

by:objects
ID: 12576091
you'll also only get that event fired if you are calling setVisible().
Is this the case?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:cathalmchale
ID: 12581682
>>  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
 
LVL 92

Expert Comment

by:objects
ID: 12581752
can u post that example?
0
 

Author Comment

by:cathalmchale
ID: 12581788
 // 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
 
LVL 92

Accepted Solution

by:
objects earned 1500 total points
ID: 12581894
whats in the listener is not important, it is how it is made visible that determines whether the listener gets called.
0
 

Author Comment

by:cathalmchale
ID: 12582034
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
 
LVL 92

Expert Comment

by:objects
ID: 12582202
how come you don't already know when it is being displayed?
0
 

Author Comment

by:cathalmchale
ID: 12582224
>>  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
 
LVL 92

Expert Comment

by:objects
ID: 12582271
but doesn't your code open it, so you know that it is being displayed
0
 

Author Comment

by:cathalmchale
ID: 12582277
of course
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month21 days, 6 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question