filmov
tv
Java Programming | FocusListener in Java | Java FocusListener | Java Swing tutorial | Java GUI
![preview_player](https://i.ytimg.com/vi/7FCe2KZaEXI/sddefault.jpg)
Показать описание
This is an example that discusses how to use FocusListener in Java. This is a very handy feature when you have several components and you want to monitor and handle the event when on of them gains or looses focus.
In short, all you have to do in order to work with a FocusListener is:
Create a new FocusListener
Override the methods that correspond to the events that you want to monitor about the component e.g focusGained, focusLost and customize as you wish the handling of the respective events. Now every time the
#FocusListener #JavaProgramming #JavaSwingTutorial #JavaGUI #JavaFocusListener #Javaforbeginners #JavaTutorial
The interface FocusListener is used for receiving keyboard focus events. The class that processes focus events needs to implements this interface.
How to Write a Focus Listener
Focus events are fired whenever a component gains or loses the keyboard focus. This is true whether the change in focus occurs through the mouse, the keyboard, or programmatically. To get familiar with basic focus concepts or to obtain detailed information about focus, see How to Use the Focus Subsystem.
This section explains how to get focus events for a particular component by registering a FocusListener instance on it. To get focus for a window only, implement a WindowFocusListener instance instead. To obtain the focus status of many components, consider implementing a PropertyChangeListener instance on the KeyboardFocusManager class, as described in Tracking Focus Changes to Multiple Components in How to Use the Focus Subsystem.
The following example demonstrates focus events. The window displays a variety of components. A focus listener, registered on each component, reports every focus-gained and focus-lost event. For each event, the other component involved in the focus change, the opposite component, is reported. For example, when the focus goes from a button to a text field, a focus-lost event is fired by the button (with the text field as the opposite component) and then a focus-gained event is fired by the text field (with the button as the opposite component). Focus-lost as well as focus-gained events can be temporary. For example, a temporary focus-lost event occurs when the window loses the focus. A temporary focus-gained event occurs on popup menus.
The listener interface for receiving keyboard focus events on a component. The class that is interested in processing a focus event either implements this interface (and all the methods it contains) or extends the abstract FocusAdapter class (overriding only the methods of interest). The listener object created from that class is then registered with a component using the component's addFocusListener method. When the component gains or loses the keyboard focus, the relevant method in the listener object is invoked, and the FocusEvent is passed to it.
Java Tutorial
Our core Java programming tutorial is designed for students and working professionals. Java is an object-oriented
, class-based, concurrent, secured and general-purpose computer-programming language. It is a widely used robust technology.
What is Java?
Java is a programming language and a platform. Java is a high level, robust, object-oriented and secure programming language.
Java was developed by Sun Microsystems (which is now the subsidiary of Oracle) in the year 1995. James Gosling is known as the father of Java. Before Java, its name was Oak. Since Oak was already a registered company, so James Gosling and his team changed the name from Oak to Java.
Platform: Any hardware or software environment in which a program runs, is known as a platform. Since Java has a runtime environment (JRE) and API, it is called a platform.
Programming guru,focus listener in java,focus listener in java example,focus listener in java swing,focus listener in java javatpoint,java,gui,tutorial,Java tutorial for beginners,Java Programming,FocusListener in Java,Java focuslistener,Java swing tutorial,java gui,SWING - FocusListener Interface,How to Write a Focus Listener,FocusListener example,Focus Listener in java,Focus Event and Focus Listener in Java,Focus Listener Interface
In short, all you have to do in order to work with a FocusListener is:
Create a new FocusListener
Override the methods that correspond to the events that you want to monitor about the component e.g focusGained, focusLost and customize as you wish the handling of the respective events. Now every time the
#FocusListener #JavaProgramming #JavaSwingTutorial #JavaGUI #JavaFocusListener #Javaforbeginners #JavaTutorial
The interface FocusListener is used for receiving keyboard focus events. The class that processes focus events needs to implements this interface.
How to Write a Focus Listener
Focus events are fired whenever a component gains or loses the keyboard focus. This is true whether the change in focus occurs through the mouse, the keyboard, or programmatically. To get familiar with basic focus concepts or to obtain detailed information about focus, see How to Use the Focus Subsystem.
This section explains how to get focus events for a particular component by registering a FocusListener instance on it. To get focus for a window only, implement a WindowFocusListener instance instead. To obtain the focus status of many components, consider implementing a PropertyChangeListener instance on the KeyboardFocusManager class, as described in Tracking Focus Changes to Multiple Components in How to Use the Focus Subsystem.
The following example demonstrates focus events. The window displays a variety of components. A focus listener, registered on each component, reports every focus-gained and focus-lost event. For each event, the other component involved in the focus change, the opposite component, is reported. For example, when the focus goes from a button to a text field, a focus-lost event is fired by the button (with the text field as the opposite component) and then a focus-gained event is fired by the text field (with the button as the opposite component). Focus-lost as well as focus-gained events can be temporary. For example, a temporary focus-lost event occurs when the window loses the focus. A temporary focus-gained event occurs on popup menus.
The listener interface for receiving keyboard focus events on a component. The class that is interested in processing a focus event either implements this interface (and all the methods it contains) or extends the abstract FocusAdapter class (overriding only the methods of interest). The listener object created from that class is then registered with a component using the component's addFocusListener method. When the component gains or loses the keyboard focus, the relevant method in the listener object is invoked, and the FocusEvent is passed to it.
Java Tutorial
Our core Java programming tutorial is designed for students and working professionals. Java is an object-oriented
, class-based, concurrent, secured and general-purpose computer-programming language. It is a widely used robust technology.
What is Java?
Java is a programming language and a platform. Java is a high level, robust, object-oriented and secure programming language.
Java was developed by Sun Microsystems (which is now the subsidiary of Oracle) in the year 1995. James Gosling is known as the father of Java. Before Java, its name was Oak. Since Oak was already a registered company, so James Gosling and his team changed the name from Oak to Java.
Platform: Any hardware or software environment in which a program runs, is known as a platform. Since Java has a runtime environment (JRE) and API, it is called a platform.
Programming guru,focus listener in java,focus listener in java example,focus listener in java swing,focus listener in java javatpoint,java,gui,tutorial,Java tutorial for beginners,Java Programming,FocusListener in Java,Java focuslistener,Java swing tutorial,java gui,SWING - FocusListener Interface,How to Write a Focus Listener,FocusListener example,Focus Listener in java,Focus Event and Focus Listener in Java,Focus Listener Interface
Комментарии