本文整理汇总了Java中java.awt.event.FocusListener类的典型用法代码示例。如果您正苦于以下问题:Java FocusListener类的具体用法?Java FocusListener怎么用?Java FocusListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FocusListener类属于java.awt.event包,在下文中一共展示了FocusListener类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getA11YJTextFieldSupport
import java.awt.event.FocusListener; //导入依赖的package包/类
/**
* Get universal Focus listener suitable for decsription JTextFields only.
* It provides screen reades support for read only enabled descriptions.
*/
public static synchronized FocusListener getA11YJTextFieldSupport() {
if (flis == null) {
flis = new java.awt.event.FocusListener() {
public void focusGained(java.awt.event.FocusEvent e) {
if (e.getComponent() instanceof javax.swing.JTextField) {
((javax.swing.JTextField)e.getComponent()).selectAll();
}
}
public void focusLost(java.awt.event.FocusEvent e) {
if (e.getComponent() instanceof javax.swing.JTextField) {
((javax.swing.JTextField)e.getComponent()).select(1,1);
}
}
};
}
return flis;
}
示例2: focusLost
import java.awt.event.FocusListener; //导入依赖的package包/类
/** Delegates to the original listener.
*/
@Override public void focusLost(FocusEvent ev) {
FocusListener l = (FocusListener) super.get(ev);
if (l != null) {
l.focusLost(ev);
}
}
示例3: createAndShowGUI
import java.awt.event.FocusListener; //导入依赖的package包/类
private static void createAndShowGUI() {
tab = new JTabbedPane();
tab.add("Tab1", new JButton("Button1"));
tab.add("Tab2", new JButton("Button2"));
tab.setMnemonicAt(0, KeyEvent.VK_T);
tab.setMnemonicAt(1, KeyEvent.VK_B);
JFrame frame = new JFrame();
frame.getContentPane().add(tab, BorderLayout.CENTER);
txtField = new JTextField();
frame.getContentPane().add(txtField, BorderLayout.NORTH);
listener = new bug4624207();
txtField.addFocusListener((FocusListener) listener);
frame.pack();
frame.setVisible(true);
}
示例4: use
import java.awt.event.FocusListener; //导入依赖的package包/类
public void use( Association<T> actualAssociation )
{
actual = actualAssociation;
T value = null;
if( actualAssociation != null )
{
value = actualAssociation.get();
}
stateModel.use( value );
for( JComponent component : components )
{
SwingAdapter adapter = adapters.get( component.getClass() );
adapter.fromAssociationToSwing( component, actualAssociation );
for( FocusListener listener : component.getFocusListeners() )
{
if( AssociationFocusLostListener.class.isInstance( listener ) )
{
( (AssociationFocusLostListener) listener ).use( adapter, actual );
}
}
}
}
示例5: use
import java.awt.event.FocusListener; //导入依赖的package包/类
public void use( Property<T> actualProperty )
{
T value = null;
if( actualProperty != null )
{
value = actualProperty.get();
}
stateModel.use( value );
for( JComponent component : components )
{
SwingAdapter adapter = adapters.get( component.getClass() );
adapter.fromPropertyToSwing( component, actualProperty );
for( FocusListener listener : component.getFocusListeners() )
{
if( PropertyFocusLostListener.class.isInstance( listener ) )
{
( (PropertyFocusLostListener) listener ).use( adapter, actualProperty );
}
}
}
}
示例6: testUndecorateTextComponent
import java.awt.event.FocusListener; //导入依赖的package包/类
/**
* SwingX Issue #299.
*/
@Test
public void testUndecorateTextComponent() {
JTextField textField = new JTextField();
AutoCompleteDecorator.decorate(textField, Collections.emptyList(), true);
AutoCompleteDecorator.undecorate(textField);
assertThat(textField.getInputMap(), is(not(instanceOf(AutoComplete.InputMap.class))));
assertThat(textField.getActionMap().get("nonstrict-backspace"), is(nullValue()));
for (FocusListener l : textField.getFocusListeners()) {
assertThat(l, is(not(instanceOf(AutoComplete.FocusAdapter.class))));
}
assertThat(textField.getDocument(), is(not(instanceOf(AutoCompleteDocument.class))));
}
示例7: init
import java.awt.event.FocusListener; //导入依赖的package包/类
public void init() {
EditorAndViewerMouseListener editorAndViewerMouseListener
= new EditorAndViewerMouseListener(this);
RichTextEditorKeyListener richTextEditorKeyListener
= new RichTextEditorKeyListener(new EditorKeyListener(getConceptPanel(),this), this);
super.init(
new RichTextToHtmlTransformer(),
richTextEditorKeyListener,
new ViewerKeyListener(getConceptPanel(),this),
new EditorFocusListener(getConceptPanel()),
(FocusListener)null,
editorAndViewerMouseListener,
editorAndViewerMouseListener,
new TextAnnotationToolbar(this));
}
示例8: removeAllListeners
import java.awt.event.FocusListener; //导入依赖的package包/类
/**
* Removes all listeners associated with the given Component. This is useful when removing to to make sure
* it does not stick around.
*/
public static void removeAllListeners(Component com) {
for (FocusListener fl : com.getFocusListeners()) {
com.removeFocusListener(fl);
}
for (MouseListener ml : com.getMouseListeners()) {
com.removeMouseListener(ml);
}
for (MouseMotionListener mml : com.getMouseMotionListeners()) {
com.removeMouseMotionListener(mml);
}
for (KeyListener kl : com.getKeyListeners()) {
com.removeKeyListener(kl);
}
for (ComponentListener cl : com.getComponentListeners()) {
com.removeComponentListener(cl);
}
}
示例9: setFocusListener
import java.awt.event.FocusListener; //导入依赖的package包/类
/**
* sets a FocusListener
*
* @param l
* the FocusListener
*/
public void setFocusListener(FocusListener l) {
this.titleTF.addFocusListener(l);
this.artistTF.addFocusListener(l);
this.albumArtistTF.addFocusListener(l);
this.albumTF.addFocusListener(l);
this.yearTF.addFocusListener(l);
this.maxTracksTF.addFocusListener(l);
this.maxCDTF.addFocusListener(l);
this.commentTF.addFocusListener(l);
this.composerTF.addFocusListener(l);
this.origArtistTF.addFocusListener(l);
this.copyrightTF.addFocusListener(l);
this.urlTF.addFocusListener(l);
this.encodedByTF.addFocusListener(l);
this.trackTF.addFocusListener(l);
this.cdTF.addFocusListener(l);
this.publisherTF.addFocusListener(l);
this.genreCB.addFocusListener(l);
this.lyricsTA.addFocusListener(l);
}
示例10: getListeners
import java.awt.event.FocusListener; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T extends EventListener> T[] getListeners(Class<T> listenerType) {
if (ComponentListener.class.isAssignableFrom(listenerType)) {
return (T[]) getComponentListeners();
} else if (FocusListener.class.isAssignableFrom(listenerType)) {
return (T[]) getFocusListeners();
} else if (HierarchyBoundsListener.class.isAssignableFrom(listenerType)) {
return (T[]) getHierarchyBoundsListeners();
} else if (HierarchyListener.class.isAssignableFrom(listenerType)) {
return (T[]) getHierarchyListeners();
} else if (InputMethodListener.class.isAssignableFrom(listenerType)) {
return (T[]) getInputMethodListeners();
} else if (KeyListener.class.isAssignableFrom(listenerType)) {
return (T[]) getKeyListeners();
} else if (MouseWheelListener.class.isAssignableFrom(listenerType)) {
return (T[]) getMouseWheelListeners();
} else if (MouseMotionListener.class.isAssignableFrom(listenerType)) {
return (T[]) getMouseMotionListeners();
} else if (MouseListener.class.isAssignableFrom(listenerType)) {
return (T[]) getMouseListeners();
} else if (PropertyChangeListener.class.isAssignableFrom(listenerType)) {
return (T[]) getPropertyChangeListeners();
}
return (T[]) Array.newInstance(listenerType, 0);
}
示例11: TextComponent
import java.awt.event.FocusListener; //导入依赖的package包/类
TextComponent() {
state = new State();
editable = true;
dispatchToIM = true; // had been disabled by createBehavior()
setFont(new Font("DialogInput", Font.PLAIN, 12)); // QUICK FIX //$NON-NLS-1$
document = new PlainDocument();
// text = new StringBuffer();
setTextKit(new TextKitImpl());
rootViewContext = createRootViewContext();
rootViewContext.getView().append(createView());
rootViewContext.getView().setSize(w, h);
caret = createCaret();
setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
addAWTMouseListener(getMouseHandler());
addAWTMouseMotionListener(getMotionHandler());
addAWTFocusListener((FocusListener) caret);
addAWTKeyListener(new KeyHandler());
// document handler must be added after caret's listener has been added!
document.addDocumentListener(new DocumentHandler());
}
示例12: testAddRemoveFocusListener
import java.awt.event.FocusListener; //导入依赖的package包/类
public final void testAddRemoveFocusListener() {
assertEquals(0, comp.getFocusListeners().length);
aComponent.addFocusListener(focusListener);
FocusListener[] listeners = comp.getFocusListeners();
assertEquals(1, listeners.length);
assertSame(focusListener, listeners[0]);
assertNull(lastFocusEvent);
comp.processEvent(new FocusEvent(comp, FocusEvent.FOCUS_GAINED));
assertNotNull("focus listener called", lastFocusEvent);
lastFocusEvent = null;
aComponent.removeFocusListener(null);
listeners = comp.getFocusListeners();
assertSame(focusListener, listeners[0]);
comp.processEvent(new FocusEvent(comp, FocusEvent.FOCUS_LOST));
assertNotNull("focus listener called", lastFocusEvent);
lastFocusEvent = null;
aComponent.removeFocusListener(focusListener);
listeners = comp.getFocusListeners();
comp.processEvent(new FocusEvent(comp, FocusEvent.FOCUS_LOST, true));
assertEquals(0, listeners.length);
assertNull("listener not called", lastFocusEvent);
}
示例13: requestFocusInWindowForComponent
import java.awt.event.FocusListener; //导入依赖的package包/类
protected boolean requestFocusInWindowForComponent(final JComponent c, int maxWaitTime)
throws Exception {
FocusListener listener = addFocusListener(c);
RunnableResulted thread = new RunnableResulted() {
@Override
public void run() {
result = c.requestFocusInWindow();
}
};
SwingUtilities.invokeAndWait(thread);
if (!thread.result) {
return false;
}
synchronized (listener) {
listener.wait(maxWaitTime);
}
waitForIdle();
if (!c.isFocusOwner()) {
fail();
}
return true;
}
示例14: requestFocusForComponent
import java.awt.event.FocusListener; //导入依赖的package包/类
protected void requestFocusForComponent(final JComponent c, final boolean temporarily,
int maxWaitTime) throws Exception {
FocusListener listener = addFocusListener(c);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
c.requestFocus(temporarily);
}
});
synchronized (listener) {
listener.wait(maxWaitTime);
}
waitForIdle();
if (!c.isFocusOwner()) {
fail();
}
}
示例15: ActionsBuilder
import java.awt.event.FocusListener; //导入依赖的package包/类
public ActionsBuilder (JPanel panel, FocusListener listener) {
this.focusListener = listener;
panel.removeAll();
GroupLayout layout = (GroupLayout) panel.getLayout();
horizontalSeqGroup = layout.createSequentialGroup();
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(horizontalSeqGroup)
);
verticalParallelGroup = layout.createParallelGroup(GroupLayout.Alignment.BASELINE);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(verticalParallelGroup)
);
}