~boginw/tapaal/multiplayer

« back to all changes in this revision

Viewing changes to src/net/tapaal/swinghelpers/RequestFocusListener.java

  • Committer: Bogi Napoleon Wennerstrøm
  • Date: 2020-04-08 13:12:38 UTC
  • mfrom: (998.2.361 testbranch)
  • Revision ID: bogi.wennerstrom@gmail.com-20200408131238-6daa9ocph3zgx1ag
merged ~yrke changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package net.tapaal.swinghelpers;
 
2
 
 
3
import javax.swing.JComponent;
 
4
import javax.swing.SwingUtilities;
 
5
import javax.swing.event.AncestorEvent;
 
6
import javax.swing.event.AncestorListener;
 
7
 
 
8
public class RequestFocusListener implements AncestorListener
 
9
{
 
10
        public RequestFocusListener()
 
11
        {
 
12
        }
 
13
 
 
14
        
 
15
        public void ancestorAdded(final AncestorEvent arg0)
 
16
        {
 
17
                //JComponent component = arg0.getComponent();
 
18
                //component.requestFocusInWindow();
 
19
                
 
20
                 final AncestorListener al= this;   
 
21
                    SwingUtilities.invokeLater(() -> {
 
22
                                JComponent component = arg0.getComponent();
 
23
                                component.requestFocusInWindow();
 
24
                                component.removeAncestorListener( al );
 
25
                        });
 
26
        }
 
27
 
 
28
        public void ancestorMoved(AncestorEvent arg0) {
 
29
                // TODO Auto-generated method stub
 
30
                
 
31
        }
 
32
 
 
33
 
 
34
        public void ancestorRemoved(AncestorEvent arg0) {
 
35
                // TODO Auto-generated method stub
 
36
                
 
37
        }
 
38
}