source: josm/trunk/src/org/openstreetmap/josm/gui/widgets/SelectAllOnFocusGainedDecorator.java@ 13652

Last change on this file since 13652 was 12304, checked in by michael2402, 7 years ago

Javadoc for public methods / classes in gui.util and gui.widgets

  • Property svn:eol-style set to native
File size: 904 bytes
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.widgets;
3
4import java.awt.Component;
5import java.awt.event.FocusAdapter;
6import java.awt.event.FocusEvent;
7
8import javax.swing.text.JTextComponent;
9
10/**
11 * A helper class that selects all text as soon as a {@link JTextComponent} receives focus.
12 */
13public class SelectAllOnFocusGainedDecorator extends FocusAdapter {
14
15 /**
16 * Add the listener to a given text component.
17 * @param tc The text component.
18 */
19 public static void decorate(JTextComponent tc) {
20 if (tc == null) return;
21 tc.addFocusListener(new SelectAllOnFocusGainedDecorator());
22 }
23
24 @Override
25 public void focusGained(FocusEvent e) {
26 Component c = e.getComponent();
27 if (c instanceof JTextComponent) {
28 JTextComponent tc = (JTextComponent) c;
29 tc.selectAll();
30 }
31 }
32}
Note: See TracBrowser for help on using the repository browser.