View RSS Feed

Actions

Swing Actions

  1. How to Write a Mouse-Wheel Listener

    by , 04-26-2012 at 08:39 PM
    When mouse’s wheel get rotated, it is been notified by the mouse wheel events. All mice don’t have wheels and in those cases generation of mouse wheel events is never done. No other way is present to detect programmatically that whether mouse wheel is present in a mouse or not.

    MouseAdapter AWT class shall be used alternatively that would be implementing the interface MouseWheelListener, for creation of the MouseWheelEvent and overriding the specific event methods.
    It is not ...
    Categories
    Actions
  2. How to Write a Mouse Listener

    by , 04-26-2012 at 08:38 PM
    To do interaction with a component, mouse is used by the user and this is notified by the mouse events. Usually mouse events take place when cursor gets entered or exit from onscreen area of the component and when button of mouse is pressed or released.

    To track down the motion of cursor usually involve more system;s overheads as compared to tracking of the other events. This is the reason why mouse motion events have been placed separately in Mouse motion, listener type.
    ...
    Categories
    Actions
  3. How to Write a List Selection Listener

    by , 04-26-2012 at 08:37 PM
    When selection of table or list is changed or is changing, then list selection event takes place. From an object, these list selection events get fired which result in implementation of interface ListSelectionModel. To get the list selection model of the table, either use getColumnModel().getSelectionModel() or getSelectionModel method.

    For detection of the list selection events, register listener at the list selection model which is appropriate. An option to register the listener ...
    Categories
    Actions
  4. How to Write a Key Listener

    by , 04-26-2012 at 08:33 PM
    Key events are being indicated when user starts typing keyboard. Key events are specifically fired with keyboard focus by the component when keyboard keys are pressed or releaserd. “How Focus Subsytem could be used” shall be read for more information regarding focus.

    Regarding 2 key events, the notifications are being sent.

    • Unicode character typing
    • To pressor release a key present at the keyboard

    First event is known as key typed event. Second ...
    Tags: key listener Add / Edit Tags
    Categories
    Actions
  5. How to Write an Item Listener

    by , 04-26-2012 at 08:32 PM
    Components fire the item events which are involved in implementation of the interface ItemSelectable. ItemSelectable components usually maintain off and on state for the items. Swing components involved in firing items include certain buttons, for example, check menu items, combo boxes, check boxes and toggle buttons etc.
    Code for the item event handling that has been taken by ComponentEventDemo.java.

    Java Code:
    //where initialization occurs
    checkbox.addItemListener(this);
    ...
    Categories
    Actions
  6. How to Write an Internal Frame Listener

    by , 04-26-2012 at 08:31 PM
    WindowListener and InternalFrameListener are similar. Just like the window listener, events are listened by the internal frame listeners which take place as window is being shown for very 1st time or are iconified, disposed of, activated, deiconified or deactivated.

    Following figure shows the application in which internal frame events have been demonstrated. Internal frame events are being listened by the application by the Event Generator frame, which display messages describing ...
    Categories
    Actions
  7. How to Write a Focus Listener

    by , 04-26-2012 at 08:30 PM
    When keyboard focus is being gained or lost by the component, focus events usually get fired. This is applicable no matter change in focus would be occurring via keyboard, mouse or programmatically.

    Here is will be explained that how focus events could be obtained for a component by making a FocusListener instance registered at it. Only for window, focus can be obtained by implementation of the WindowFocusListener instance. For many components implementation of the PropertyChangeListener ...
    Categories
    Actions
  8. How to Write a Document Listener

    by , 04-26-2012 at 08:29 PM
    A document is used by the swing text component for representation of its components. When document’s content changes, document events take place. A document listener is attached to the text of document of the component instead of the text component, itself.

    Document events are demonstrated by the given example, at 2 text components.

    Name:  1.jpg
Views: 601
Size:  16.1 KB
    Document Listener
    Categories
    Actions
  9. How to Write a Container Listener

    by , 04-26-2012 at 08:27 PM
    A container is involved in firing the Container events; right after the component gets added/removed. Such kinds of events are just for sake of notifications. Container listeners are not needed to be there for adding or removing the components successfully.

    Container events are demonstrated by the given example. Click at ADD A BUTTON /Remove Button to add or remove buttons from the panel which is present at the window’s bottom. Everytime button is added/removed, container event is ...
    Categories
    Actions
  10. How to Write a Component Listener

    by , 04-26-2012 at 08:26 PM
    Component listener is considered as a listener interface to receive the component events. Component is that object which has a graphical presentation which might be displayed at screen or may also interact with some user. Few component examples are scrollbars, checkboxes and buttons of graphical interface.

    Class involved in component event processing will be implementing this interface along with all of the contained methods or will be extending the abstract ComponentAdapter. Listener ...
    Categories
    Actions
  11. How to Write a Change Listener

    by , 04-26-2012 at 08:24 PM
    Property change listener and a change listener are similar. On an object, change listener gets register, typically at component. However, it may be some other object and when object is changed notification is sent to the listener. In case of change listener, notification of any sort of change is not sent to the listener but changing of the source object is notified. Hence, change listeners are considered as more useful only when it becomes necessary to be aware that when object gets changed. ...
    Categories
    Actions
  12. How to Write a Caret Listener

    by , 04-26-2012 at 08:23 PM
    In text component when selection gets changed or moved by the caret (i.e the cursor which show insertion point), caret events take place. Document of the text component may be initiating the caret event when text is inserted or removed. Caret listener may be attached to any subclass of the JTextComponent instance with method addCaretListener.
    Categories
    Actions
  13. How to Write an Action Listener

    by , 04-26-2012 at 08:22 PM
    Action Listeners are the most common and easiest event handlers for implementation. An action listener is implemented to detail that what could be possibly done when cetain operations are performed by user.

    When a user performs an action, an action event takes place. For example, when a button is clicked by a user, menu item is choosen and in text field ENTER is pressed. An actionPerformed message would be sent to all of the action listeners , which on a relevant component are registered. ...
    Categories
    Actions
  14. Sending a Description of an Action to a Status Bar

    by , 04-26-2012 at 08:22 PM
    Requested feature that is more common is that architecture which supports the content messages sending to status bar, when mouse is present at toolbar buttons or menu items. Support will be provided by the architecture of current action which behaves elegantly.
    When and addition of action is done to a container like JMenu or JToolBar, component which got added to container, is returned. MouseAdapter’s shared instance is added, to returned components. When at component the mouse is moved, ...
    Tags: status bar Add / Edit Tags
    Categories
    Actions
  15. Enabling and Disabling of Components Which Share an Action

    by , 04-26-2012 at 07:50 PM
    When “enabled”, the bound property of Action is enabled/disabled, property change event is sent to property change listeners. The AbstractButton consist of “inner-class property change listener” that disables/enables the correspondent component.

    In case of ActionDemo applications, actions get initialized in initActions() method. Similar Actions set is shared among popup menu, toolbar, menu and also are used for construction of the UI controls in createPopupMenu(),createToolBar() and ...
    Categories
    Actions
  16. Interface Action

    by , 04-26-2012 at 07:49 PM
    A useful extension is provided by the Action interface to the Action Listener interface where multiple controls may access similar functionality.
    ActionPerformed method that has been defined by the help of ActionListener interface, this interface would be allowing application to define:

    • One or more than one text strings that provide details regarding the function. Strings could be used for display of the button;s flyover text or setting up of the text, in menu item.
    • One
    ...
    Categories
    Actions
  17. How to Use Actions

    by , 04-26-2012 at 07:48 PM
    For separation of the state and functionality from component, an action is used. For instance, if there are 2 or more than 2 components which perform similar kind of functions, an Action object shall be considered for implementation of the function. An action object act as action listener which assist action event handling as well as centralized handling for component of action event firing state. For example, text fields, common buttons, menu items and tool bar buttons. The state which can be handled ...
    Categories
    Actions
  18. Swing Action architecture

    by , 01-08-2012 at 12:28 PM
    Shared behavior between different user interfaces components are implemented by “Swing Action Architecture”. Like tool bar buttons and menu items perform same actions. All the components are disabled when an action is disabled.

    Java Code: Swing Action Architecture
    class FileAction extends AbstractAction {
    //Constructor
    FileAction(String name) {
    super(name);
    }
    public void actionPerformed(ActionEvent ae){
    //add action logic here
    }
    }
    JMenu fileMenu
    ...

    Updated 01-14-2012 at 06:56 PM by Java Swing

    Categories
    Architecture , Actions