title: Dynamically added Components in TopComponent won't show
body: <p>I'm running in a quite strange problem while programming with the Netbean platform 7.3, based on Geertjan's blog example on how to add widgets through actions (<a href="https://blogs.oracle.com/geertjan/entry/add_widget_via_action_in" rel="nofollow">https://blogs.oracle.com/geertjan/entry/add_widget_via_action_in</a>) :</p>
  
  <p>I created a TopComponent, and I want it to show a custom ScrollPane rendering images in a custom pane. My custom Scrollpane is working nice in a basic Java Swing application.</p>
  
  <p>I tried to display the Scrollpane in the TopComponent's constructor, just to test :</p>
  
  <pre><code>  public TopComponent()
      {
          super();
          setBackground( Color.BLUE );
          initComponents();
          setName( Bundle.CTL_Scanmage2TopComponent() );
          setToolTipText( Bundle.HINT_Scanmage2TopComponent() );
          setImage( ImageHandlerFactory.getImageHandler( new File( ... ) ));
      }
  </code></pre>
  
  <p>There is the setImage method the <code>ImageHandler</code> is a class of mine describing an image :</p>
  
  <pre><code>public void setImage( ImageHandler handler ) throws Exception
  {
      pane = new Scrollpane(); // pane is a class field of type : Scrollpane
  
      pane.setImage( handler ); // thats OK, the tiled image is loaded, etc.
  
      setLayout( new BorderLayout() );
  
      add( pane , BorderLayout.CENTER , 0 );
  
      pane.revalidate(); // does not work
      pane.repaint(); // does not work
  }
  </code></pre>
  
  <p>All OK, the netbeans application launches, the image is well displayed in the application <em>only when setImage is called from constructor or from componentOpened</em>.</p>
  
  <p>Now, I would load the image through a menu, I implemented an interface, a service provider, all OK.</p>
  
  <p>From the menu action, I use the lookup to find all objects having the method to load the image through the ImageHandler generated from this action.</p>
  
  <p>Then, calling <code>setImage(...)</code> through the Lookup does nothing, my TopComponent absolutely refuses to display anything.</p>
  
  <p>I tried to use a <code>FlowLayout</code>, thus displaying a small (about 3x3 pix) thing in the top of the TopComponent.</p>
  
  <p>The question is : how can I force the TopComponent to paint the Scrollpane (extends JScrollpane) I put into it ?</p>
  
  <p>I tried to revalidate / validate / invalidate / repaint / ... the TopComponent, the Scrollpane, but no way...</p>
  
  <p>Any idea ?</p>
  
  <p>Thanks !</p>
  
  <p><strong>-- EDIT 1 / reedited : unuseful parts deleted --</strong></p>
  
  <p>Geertjan's app still works fine, but calling the setImage method from the button's action does nothing.</p>
  
  <p>Here is the code of this button :</p>
  
  <pre><code>public void actionPerformed( ActionEvent e )
  {
      Lookup.Result&lt;MyInterface &gt; controllers = Lookup.getDefault().lookupResult( MyInterface .class );
      Collection&lt;? extends MyInterface &gt; controllersColl = controllers.allInstances();
      for( MyInterface c : controllersColl )
      {
          c.setImage( imgH ); // debug shows it passes heres and expected internal job is done
      }
  }
  </code></pre>
  
  <p>All seems to go OK, objects are created, etc. but nothing visible happens in the GUI.</p>
  
  <p><strong>-- EDIT 2 / reedited : unuseful parts deleted --</strong></p>
  
  <p><strong>-- EDIT 3 / after Tan Hui Onn answer --</strong></p>
  
  <p>Indeed, that was it, thanks Tan Hui Onn : "you will just get another instance of TopComponent".</p>
  
  <p>Using <code>TopComponent.getRegistry().getActivated()</code> does the job.</p>