Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

focus problem

 
selvas kumars
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks,
when window gets focus i want fire my method where both gained focus and lost focus are not getting executed..
thanks,
silva.
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.util.Vector;
import java.awt.event.FocusListener;
import java.awt.event.FocusEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowAdapter;
public class FocusEventDemo extends JFrame {
public FocusEventDemo(){
show();
addFocusListener(new fa(){

public void focusGained(FocusEvent e) {
System.out.println("focus gained fired");
}
public void focusLost(FocusEvent e) {
System.out.println("focus gained fired");
}
});
}
public static void main(String args[]){
FocusEventDemo demo = new FocusEventDemo();
}
}
class fa extends FocusAdapter{
}

 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Selvas,
If you are interested in windows then you should be using WindowListener --> windowActivated, windowDeactivated
For windows that should be equivalent for focus gained and lost on any other component.
Regards,
Manfred.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic