Get default Actions from JTextArea in Java
Description
The following code shows how to get default Actions from JTextArea.
Example
/*from w w w . j a v a 2 s . c o m*/
import java.util.Arrays;
import java.util.Comparator;
import javax.swing.Action;
import javax.swing.JTextArea;
import javax.swing.text.JTextComponent;
public class Main {
public static void main(String args[]) {
JTextComponent component = new JTextArea();
// Process action list
Action actions[] = component.getActions();
// Define comparator to sort actions
Comparator<Action> comparator = new Comparator<Action>() {
public int compare(Action a1, Action a2) {
String firstName = (String) a1.getValue(Action.NAME);
String secondName = (String) a2.getValue(Action.NAME);
return firstName.compareTo(secondName);
}
};
Arrays.sort(actions, comparator);
int count = actions.length;
System.out.println("Count: " + count);
for (int i = 0; i < count; i++) {
System.out.printf("%28s : %s\n",actions[i].getValue(Action.NAME),actions[i].getClass().getName());
}
}
}
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »