Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show Event for JTextField in Java?

I'm implementing a specialized version of JTextField and want to pack it into an own bean. The bean works pretty fine so far. Here's my question:

How can I detect when the JTextField is shown? So that I can init some graphical stuff everytime the fields are shown.

The ShowComponent event does not work for me. FocusGained and FocusLost works just fine.

Hope there's somebody who knows the solution to this.

like image 245
salocinx Avatar asked Feb 08 '12 23:02

salocinx


2 Answers

Can you use the isShowing() method? http://docs.oracle.com/javase/7/docs/api/java/awt/Component.html#isShowing%28%29

like image 102
Atif Avatar answered Oct 23 '22 09:10

Atif


While using a ComponentListener and doing stuff in its componentShown intuitively seems to be the way to go, it doesn't help: it fires when the component's visible property is changed. That property is true by default (even if not yet added to any container showing on the screen), and consequently nothing fired on showing ..

Instead, use an AncestorListener and do what's needed in its ancestorAdded.

like image 40
kleopatra Avatar answered Oct 23 '22 10:10

kleopatra