20 package net.sf.gridarta.gui.utils;
22 import java.awt.Component;
23 import java.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
25 import java.awt.event.FocusEvent;
26 import java.awt.event.FocusListener;
27 import javax.swing.JTextField;
28 import javax.swing.text.JTextComponent;
29 import org.jetbrains.annotations.NotNull;
49 final FocusListener focusListener =
new FocusListener() {
52 public void focusGained(@NotNull
final FocusEvent e) {
53 textComponent.selectAll();
57 public void focusLost(@NotNull
final FocusEvent e) {
62 textComponent.addFocusListener(focusListener);
70 public static void setActionNextFocus(@NotNull
final JTextField textField, @NotNull
final Component nextComponent) {
71 final ActionListener actionListener =
new ActionListener() {
74 public void actionPerformed(@NotNull
final ActionEvent e) {
75 nextComponent.requestFocusInWindow();
79 textField.addActionListener(actionListener);
Utility class for JTextComponent related functions.
static void setAutoSelectOnFocus(@NotNull final JTextComponent textComponent)
Selects all text of a JTextComponent when the component gains the focus.
TextComponentUtils()
Private constructor to prevent instantiation.
static void setActionNextFocus(@NotNull final JTextField textField, @NotNull final Component nextComponent)
Transfers the focus to another component when ENTER is pressed.