~boginw/tapaal/multiplayer

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package net.tapaal.swinghelpers;

import javax.swing.JComponent;
import javax.swing.SwingUtilities;
import javax.swing.event.AncestorEvent;
import javax.swing.event.AncestorListener;

public class RequestFocusListener implements AncestorListener
{
	public RequestFocusListener()
	{
	}

	
	public void ancestorAdded(final AncestorEvent arg0)
	{
		//JComponent component = arg0.getComponent();
		//component.requestFocusInWindow();
		
		 final AncestorListener al= this;   
		    SwingUtilities.invokeLater(() -> {
				JComponent component = arg0.getComponent();
				component.requestFocusInWindow();
				component.removeAncestorListener( al );
			});
	}

	public void ancestorMoved(AncestorEvent arg0) {
		// TODO Auto-generated method stub
		
	}


	public void ancestorRemoved(AncestorEvent arg0) {
		// TODO Auto-generated method stub
		
	}
}