Thursday, January 17, 2013

Solution for: compenentShown() does not called when the visibilitiy of JPanel changed.

Use an AncestorListener as described in dialog focus.
When a JDialog (or JFrame for that matter) is made visible, focus is placed on the first focusable component by default. There may be times when you want to change this behaviour. The obvious solution would be to invoke the requestFocusInWindow() method on the component you wish to receive focus. The problem is that this doesn’t work all the time.
The problem is .. a component can’t request focus unless it has been added to a “realized” dialog. A realized dialog basically means that the Swing JDialog has been added to a peer component that represents a dialog on the underlying OS. This occurs when you invoke the pack() or setVisible(true) methods on the JDialog.
And that is where the ancestor listener comes in handy. For a component in a modal dialog, it will be fired once the component becomes visible, and is realized & focusable.
Edit: The above comment applies to components in any Swing container, including JFrame and JPanel.

Thread copied from

1 comment:

  1. One thing’s certain – you’ll by no means find a recreation like Bitstarz Billion in Vegas. Regardless, their certified agents tackle questions and considerations 24 hours a day. Better still, they concern lightning-fast 온라인카지노 responses that don’t beat across the bush. We acquired an instant chat reply from an actual particular person inside 5 seconds of sending a “test” message. On that note, big-fish hunters in search of big prizes will appreciate Ignition’s “Hot Drop” Jackpots. Notably, NeoSurf and crypto depositors will claim an extra 20% bonus.