abstractaction

Java example: JMenuBar + KeyStroke + AbstractAction

As a brief note, here’s some source code that I used to create a JMenuBar in a Java application. First, I defined some fields in my main class:

private static final KeyStroke fileOpenKeystroke = KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.META_MASK);
private Action fileOpenAction;
private JMenuBar menuBar;

Later in the same class I defined this method:

A Java Command Design Pattern example

Summary: A Java “Command Pattern” example is demonstrated.

If you've ever seen Java source code that looks like this:

A Java Action, ActionListener, and AbstractAction example

Java Swing FAQ: Can you provide a complete example of how to use the Java Action interface and the Java AbstractAction class?

The Java Action interface and AbstractAction class are terrific ways of encapsulating behaviors (logic), especially when an action can be triggered from more than one place in your Java/Swing application.

JButton tutorials and examples

Continuing with the organization efforts again today, here is a collection of Java JButton tutorials and examples:

Java undo and redo in a Swing application

Here's a step-by-step approach for how to implement "undo" and "redo" behavior in your Java text components, i.e., the JTextArea JEditorPane and JTextPane I should note that you don't get this behavior for free -- you have to implement it yourself, hence this undo/redo tutorial.