Article View: borland.public.jbuilder.java.swing
Article #9806componentShown/Hidden not working in Swing?
From: Jos van Roosmalen
Date: Mon, 31 Jan 2000 00:00
Date: Mon, 31 Jan 2000 00:00
59 lines
2146 bytes
2146 bytes
Hello,
Does someone know how I can get a notification when a
JComponent(JPanel/Button etc), become visible or hide? I used a
ComponentListener but that's not working. The example below,
generate only a resize ComponentEvent(because of the LayoutManager).
If this is a bug: how can I work arround this bug on a easy way: getting a
notification when a component become visible or hide.
If this is not a bug: what I am doing wrong?
Thanks!
Jos
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Test extends JFrame
{
public static void main(String[] args)
{
Test test=new Test();
test.setVisible(true);
}
public Test()
{
setBounds(10,10,300,300);
// setLayout(null); // without setLayout(null) -> resized componentEvent
JPanel panel=new JPanel();
panel.setBackground(Color.blue);
getContentPane().add(panel);
panel.addComponentListener(new PanelListener());
}
class PanelListener implements ComponentListener
{
public void componentShown(ComponentEvent e)
{
System.out.println("Panel shown");
}
public void componentHidden(ComponentEvent e)
{
System.out.println("Panel hidden");
}
public void componentResized(ComponentEvent e)
{
System.out.println("Panel resized");
}
public void componentMoved(ComponentEvent e)
{
System.out.println("Panel moved");
}
}
}
Technical Details
Message-ID:
<874uff$ojn$1@news1.xs4all.nl>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,8d3945db8af22cd6,start X-Google-Attributes: gid111d45,public From: "Jos van Roosmalen" <cmp@xs4all.nl> Subject: componentShown/Hidden not working in Swing? Date: 2000/01/31 Message-ID: <874uff$ojn$1@news1.xs4all.nl> X-Deja-AN: 580055734 X-Priority: 3 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 X-Complaints-To: abuse@xs4all.nl X-Trace: news1.xs4all.nl 949353775 25207 194.109.133.204 (31 Jan 2000 21:22:55 GMT) Organization: XS4ALL Internet BV X-MSMail-Priority: Normal NNTP-Posting-Date: 31 Jan 2000 21:22:55 GMT Newsgroups: borland.public.jbuilder.java.swing