Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

ComponentListener?

Thread view: 
Knute Johnson - 17 Nov 2006 23:41 GMT
What am I doing wrong with this ComponentListener?  It never calls
componentShown();

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class test extends JPanel {
    public test() {
        setPreferredSize(new Dimension(200,200));

        addComponentListener(new ComponentAdapter() {
            public void componentShown(ComponentEvent ce) {
                System.out.println(ce);
            }
        });
    }

    public static void main(String[] args) {
        Runnable r = new Runnable() {
            public void run() {
                JFrame f = new JFrame();
                f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                test t = new test();
                f.add(t);
                f.pack();
                f.setVisible(true);
            }
        };
        EventQueue.invokeLater(r);
    }
}

Signature

Knute Johnson
email s/nospam/knute/

Stefan Ram - 18 Nov 2006 00:12 GMT
>                 f.setVisible(true);

 Apparently, this does not count. Inserting

                 t.setVisible( false );
                 t.setVisible( true );

 directly after this seems to trigger the event.
Knute Johnson - 18 Nov 2006 00:49 GMT
>>                 f.setVisible(true);
>
[quoted text clipped - 4 lines]
>
>   directly after this seems to trigger the event.

Just found an interesting tidbit in the Tutorial:

"The component-hidden and component-shown events occur only as the
result of calls to a Component's setVisible method. For example, a
window might be miniaturized into an icon (iconified) without a
component-hidden event being fired."

It would have been nice if that was in the docs too.

Thanks,

Signature

Knute Johnson
email s/nospam/knute/

Christian Kaufhold - 19 Nov 2006 00:31 GMT
> What am I doing wrong with this ComponentListener?  It never calls
> componentShown();

None-Window components are visible by default (but not "showing" until
their Window is made visible). Maybe you are looking
for HierarchyListener.

Christian


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.