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.
|
---|
2 | package org.openstreetmap.josm.gui.widgets;
|
---|
3 |
|
---|
4 | import java.awt.Component;
|
---|
5 | import java.awt.event.FocusAdapter;
|
---|
6 | import java.awt.event.FocusEvent;
|
---|
7 |
|
---|
8 | import javax.swing.text.JTextComponent;
|
---|
9 |
|
---|
10 | /**
|
---|
11 | * A helper class that selects all text as soon as a {@link JTextComponent} receives focus.
|
---|
12 | */
|
---|
13 | public 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.