微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

java.awt.event.FocusListener的实例源码

项目:incubator-netbeans    文件A11YUtil.java   
/**
 * 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;
}
项目:incubator-netbeans    文件WeakListenerImpl.java   
/** Delegates to the original listener.
*/
@Override public void focusLost(FocusEvent ev) {
    FocusListener l = (FocusListener) super.get(ev);

    if (l != null) {
        l.focusLost(ev);
    }
}
项目:jdk8u-jdk    文件bug4624207.java   
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);
}
项目:openjdk-jdk10    文件bug4624207.java   
private static void createAndShowGUI() {
    tab = new JTabbedPane();
    tab.add("Tab1",BorderLayout.norTH);
    listener = new bug4624207();
    txtField.addFocusListener((FocusListener) listener);
    frame.pack();
    frame.setVisible(true);
}
项目:openjdk9    文件bug4624207.java   
private static void createAndShowGUI() {
    tab = new JTabbedPane();
    tab.add("Tab1",BorderLayout.norTH);
    listener = new bug4624207();
    txtField.addFocusListener((FocusListener) listener);
    frame.pack();
    frame.setVisible(true);
}
项目:jdk8u_jdk    文件bug4624207.java   
private static void createAndShowGUI() {
    tab = new JTabbedPane();
    tab.add("Tab1",BorderLayout.norTH);
    listener = new bug4624207();
    txtField.addFocusListener((FocusListener) listener);
    frame.pack();
    frame.setVisible(true);
}
项目:lookaside_java-1.8.0-openjdk    文件bug4624207.java   
private static void createAndShowGUI() {
    tab = new JTabbedPane();
    tab.add("Tab1",BorderLayout.norTH);
    listener = new bug4624207();
    txtField.addFocusListener((FocusListener) listener);
    frame.pack();
    frame.setVisible(true);
}
项目:polygene-java    文件BoundAssociation.java   
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 );
            }
        }
    }
}
项目:polygene-java    文件BoundProperty.java   
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 );
            }
        }
    }
}
项目:swingx    文件AutoCompleteDecoratorTest.java   
/**
 * 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))));
}
项目:mindraider    文件RichTextAnnotationRenderer.java   
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(),new EditorFocusListener(getConceptPanel()),(FocusListener)null,editorAndViewerMouseListener,new TextAnnotationToolbar(this));
}
项目:power-matchmaker    文件mungePen.java   
/**
 * 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);
    }
}
项目:infobip-open-jdk-8    文件bug4624207.java   
private static void createAndShowGUI() {
    tab = new JTabbedPane();
    tab.add("Tab1",BorderLayout.norTH);
    listener = new bug4624207();
    txtField.addFocusListener((FocusListener) listener);
    frame.pack();
    frame.setVisible(true);
}
项目:jdk8u-dev-jdk    文件bug4624207.java   
private static void createAndShowGUI() {
    tab = new JTabbedPane();
    tab.add("Tab1",BorderLayout.norTH);
    listener = new bug4624207();
    txtField.addFocusListener((FocusListener) listener);
    frame.pack();
    frame.setVisible(true);
}
项目:MP3ToolKit    文件ID3RightPanel.java   
/**
 * 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);
}
项目:cn1    文件Component.java   
@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);
}
项目:cn1    文件TextComponent.java   
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());
}
项目:cn1    文件AccessibleAWTComponentTest.java   
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);

}
项目:cn1    文件JComponent_MultithreadedTest.java   
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;
}
项目:cn1    文件JComponent_MultithreadedTest.java   
protected boolean requestFocusInWindowForComponent(final JComponent c,final boolean temporarily,int maxWaitTime) throws Exception {
    FocusListener listener = addFocusListener(c);
    RunnableResulted thread = new RunnableResulted() {
        @Override
        public void run() {
            result = c.requestFocusInWindow(temporarily);
        }
    };
    SwingUtilities.invokeAndWait(thread);
    if (!thread.result) {
        return false;
    }
    synchronized (listener) {
        listener.wait(maxWaitTime);
    }
    waitForIdle();
    if (!c.isFocusOwner()) {
        fail();
    }
    return true;
}
项目:cn1    文件JComponent_MultithreadedTest.java   
protected void requestFocusForComponent(final JComponent c,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();
    }
}
项目:incubator-netbeans    文件CollapsibleSectionPanel.java   
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)
    );
}
项目:incubator-netbeans    文件UIUtils.java   
public static void keepFocusedComponentVisible(Component component,JComponent container) {
    FocusListener listener;
    if(component instanceof JComponent ) {
        listener = getNotShowingFieldsFocusListener(container);
    } else {
        listener = getScrollingFocusListener(); // legacy fallback
    }
    keepFocusedComponentVisible(component,listener);
}
项目:incubator-netbeans    文件UIUtils.java   
private static void keepFocusedComponentVisible(Component component,FocusListener l) {
    component.removeFocusListener(l); // Making sure that it is not added twice
    component.addFocusListener(l);
    if (component instanceof Container) {
        for (Component subComponent : ((Container)component).getComponents()) {
            keepFocusedComponentVisible(subComponent,l);
        }
    }
}
项目:incubator-netbeans    文件UIUtils.java   
private static FocusListener getNotShowingFieldsFocusListener(JComponent container) {
    String key = "notShowingFieldFocusListener";                            // NOI18N
    Object l = container.getClientProperty(key);
    if (l == null) {
        l = new NotShowingFieldsFocusListener(container);
        container.putClientProperty(key,l);
    }
    return (FocusListener) l;
}
项目:incubator-netbeans    文件IconPanel.java   
public void addFocusListener(FocusListener fl) {
    if (comp != null) {
        comp.addFocusListener(fl);
    } else {
        super.addFocusListener(fl);
    }
}
项目:incubator-netbeans    文件IconPanel.java   
public void removeFocusListener(FocusListener fl) {
    if (comp != null) {
        comp.removeFocusListener(fl);
    } else {
        super.removeFocusListener(fl);
    }
}
项目:incubator-netbeans    文件ButtonPanel.java   
/** Overridden to proxy adds to the custom editor button and the
 * installed component */
public void addFocusListener(FocusListener l) {
    if (comp != null) {
        button.addFocusListener(l);
        comp.addFocusListener(l);
    }
}
项目:incubator-netbeans    文件ButtonPanel.java   
/** Overridden to proxy removes to the custom editor button and the
 * installed component */
public void removeFocusListener(FocusListener l) {
    if (comp != null) {
        button.removeFocusListener(l);
        comp.removeFocusListener(l);
    }
}
项目:incubator-netbeans    文件WeakListener.java   
/** Delegates to the original listener.
*/
public void focusGained(FocusEvent ev) {
    FocusListener l = (FocusListener) super.get(ev);

    if (l != null) {
        l.focusGained(ev);
    }
}
项目:incubator-netbeans    文件WeakListener.java   
/** Delegates to the original listener.
*/
public void focusLost(FocusEvent ev) {
    FocusListener l = (FocusListener) super.get(ev);

    if (l != null) {
        l.focusLost(ev);
    }
}
项目:incubator-netbeans    文件SectionInnerPanel.java   
public synchronized void addFocusListener(FocusListener l) {
    super.addFocusListener(l);
    if (!localFocusListenerInitialized) {
        localFocusListenerInitialized = true;
        Container container = this;
        FocusListener focusListener = localFocusListener;
        addFocusListenerRecursively(container,focusListener);
    }
}
项目:incubator-netbeans    文件SectionInnerPanel.java   
private void addFocusListenerRecursively(Container container,FocusListener focusListener) {
    final Component[] components = container.getComponents();
    for (int i = 0; i < components.length; i++) {
        Component component = components[i];
        if (component.isFocusable() && !(component instanceof JLabel)) {
            component.addFocusListener(focusListener);
        }
        if (component instanceof Container) {
            if (!(component instanceof SectionNodePanel)) {
                addFocusListenerRecursively((Container) component,focusListener);
            }
        }
    }
}
项目:incubator-netbeans    文件FixDuplicateImportStmts.java   
private JComboBox createComboBox(CandidateDescription[] choices,CandidateDescription defaultValue,Font font,FocusListener listener ) {
    JComboBox combo = new JComboBox(choices);
    combo.setSelectedItem(defaultValue);
    combo.getAccessibleContext().setAccessibleDescription(getBundleString("FixDupImportStmts_Combo_ACSD")); //NOI18N
    combo.getAccessibleContext().setAccessibleName(getBundleString("FixDupImportStmts_Combo_Name_ACSD")); //NOI18N
    combo.setopaque(false);
    combo.setFont( font );
    combo.addFocusListener( listener );
    combo.setEnabled( choices.length > 1 );
    combo.setRenderer( new DelegatingRenderer(combo.getRenderer()));
    InputMap inputMap = combo.getInputMap( JComboBox.WHEN_FOCUSED );
    inputMap.put( Keystroke.getKeystroke( KeyEvent.VK_SPACE,0),"showPopup" ); //NOI18N
    combo.getActionMap().put( "showPopup",new TogglePopupAction() ); //NOI18N
    return combo;
}
项目:incubator-netbeans    文件ResolveDeclarationsPanel.java   
private void initComponentsMore() {
    contentPanel.setLayout(new GridBagLayout());
    contentPanel.setBackground(UIManager.getColor("Table.background")); //NOI18N

    int row = 0;
    combos = new ArrayList<>(items.size());

    Font monoSpaced = new Font("Monospaced",new JLabel().getFont().getSize()); //NOI18N
    FocusListener focusListener = new FocusAdapter() {

        @Override
        public void focusGained(FocusEvent e) {
            Component c = e.getComponent();
            Rectangle r = c.getBounds();
            contentPanel.scrollRectToVisible(r);
        }

    };
    for (int i = 0; i < items.size(); i++) {
        ResolveDeclarationItem item = items.get(i);
        JComboBox jComboBox = createComboBox(item,monoSpaced,focusListener);
        combos.add(jComboBox);

        JLabel lblSimpleName = new JLabel(item.getName());
        lblSimpleName.setopaque(false);
        lblSimpleName.setFont(monoSpaced);
        lblSimpleName.setLabelFor(jComboBox);

        contentPanel.add(lblSimpleName,new GridBagConstraints(0,row,1,0.0,GridBagConstraints.WEST,GridBagConstraints.NONE,new Insets(3,5,2,5),0));
        contentPanel.add(jComboBox,new GridBagConstraints(1,row++,1.0,GridBagConstraints.HORIZONTAL,0));
    }

    contentPanel.add(new JLabel(),new GridBagConstraints(2,GridBagConstraints.CENTER,new Insets(0,0));

    Dimension d = contentPanel.getPreferredSize();
    d.height = getRowHeight() * Math.min(combos.size(),6);

}
项目:incubator-netbeans    文件WeakListenerImpl.java   
/** Delegates to the original listener.
*/
@Override public void focusGained(FocusEvent ev) {
    FocusListener l = (FocusListener) super.get(ev);

    if (l != null) {
        l.focusGained(ev);
    }
}
项目:rapidminer    文件AutoCompletionComboBox.java   
@Override
public synchronized void addFocusListener(FocusListener l) {
    // workaround for java bug #6433257
    for (Component c : getComponents()) {
        c.addFocusListener(l);
    }
}
项目:openjdk-jdk10    文件ComponentOperator.java   
/**
 * Maps {@code Component.addFocusListener(FocusListener)} through queue
 */
public void addFocusListener(final FocusListener focusListener) {
    runMapping(new MapVoidAction("addFocusListener") {
        @Override
        public void map() {
            getSource().addFocusListener(focusListener);
        }
    });
}
项目:openjdk-jdk10    文件ComponentOperator.java   
/**
 * Maps {@code Component.removeFocusListener(FocusListener)} through queue
 */
public void removeFocusListener(final FocusListener focusListener) {
    runMapping(new MapVoidAction("removeFocusListener") {
        @Override
        public void map() {
            getSource().removeFocusListener(focusListener);
        }
    });
}
项目:oxygen-git-plugin    文件StagingPanel.java   
/**
 * Adds a focus listener on the component and its descendents.
 * 
 * @param c
 *          The component.
 * @param focusListener
 *          Focus Listener.
 */
private void installFocusListener(Component c,FocusListener focusListener) {
    c.addFocusListener(focusListener);

    if (c instanceof Container) {
        Container container = (Container) c;
        int componentCount = container.getComponentCount();
        for (int i = 0; i < componentCount; i++) {
            Component child = container.getComponent(i);
            installFocusListener(child,focusListener);
        }
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。