aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JFrame & FocusListener Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JFrame & FocusListener" Watch "JFrame & FocusListener" New topic

JFrame & FocusListener

Pratik Khetia
Ranch Hand

Joined: Jun 29, 2001
Posts: 50
Hi I want to generate an event when there is a mouse click outside the JFrame window.
Like in my chat application, I open a JFrame for personal chat but when the user clicks outside that it is going into to the Windows taskbar which I want to does anybody has any idea ???
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
can't you use focusGained(FocusEvent e),focusLost(FocusEvent e) ?

All right brain, you don't like me and I don't like you, but let's just do this one thing so I can get back to killing you with beer.<br /> <br />- Homer Simpson
Pratik Khetia
Ranch Hand

Joined: Jun 29, 2001
Posts: 50
Originally posted by Alex Kravets:
can't you use focusGained(FocusEvent e),focusLost(FocusEvent e) ?

I tried using that but its not working...
Alex Kravets
Ranch Hand

Joined: Jan 24, 2001
Posts: 476
try running this example, it should work with the focusGained(), focusLost()...
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.awt.*;
public class testEvents extends JApplet implements MouseListener, FocusListener{
Container container;
JPanel aPanel, aPanel2, aPanel3;
JButton button;
JTextField text;
public void init(){
container = getContentPane();
container.setLayout(new BorderLayout());
aPanel = new JPanel();
aPanel2 = new JPanel();
text = new JTextField(20);
button = new JButton("test");
aPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(,1),"Button Response"));
container.add(aPanel2, BorderLayout.CENTER);
container.add(aPanel, BorderLayout.SOUTH);
public void mousePressed(MouseEvent e){
text.setText("You pressed a button");
public void mouseClicked(MouseEvent e){
text.setText("You clicked a mouse");
public void mouseEntered(MouseEvent e){
text.setText("You entered a mouse");
public void mouseExited(MouseEvent e){
text.setText(" ");
public void mouseReleased(MouseEvent e){
text.setText("You released a button");
public void focusGained(FocusEvent e){
text.setText("focus gained...");
public void focusLost(FocusEvent e){
text.setText("waiting for action...");
I agree. Here's the link:
subject: JFrame & FocusListener
Similar Threads
how to blink the title bar - plz help urgent
blink the title bar
idle time checking - very urgent..
Hello Friends
calling application through servlet