Java Code Examples for javax.swing.JComponent.addFocusListener()

The following are Jave code examples for showing how to use addFocusListener() of the javax.swing.JComponent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: jaer   File: PotPanel.java   View Source Code Vote up 6 votes
private void addBorderSetter(final JComponent s) {
        if (s instanceof JTextField || s instanceof JSlider || s instanceof JComboBox || s instanceof AbstractButton) {
            s.setFocusable(true);// sliders and combo boxes not normally focusable
            s.addFocusListener(this);
//            log.info("added border setter for "+s.getClass().getSimpleName());
        } else if (s instanceof Container) {
            Component[] components = s.getComponents();
            for (Component c : components) {
//                log.info("possibly adding border setter for "+c.getClass().getSimpleName());
                if (c instanceof JComponent) {
                    addBorderSetter((JComponent) c);
                }
            }
        }
    }
 
Example 2
Project: incubator-netbeans   File: RepoSelectorPanel.java   View Source Code Vote up 5 votes
RepoSelectorPanel(JComponent repoSelector,
                  JComponent newRepoButton) {
    super(null);
    JLabel repoSelectorLabel = new JLabel();

    repoSelectorLabel.setLabelFor(repoSelector);
    repoSelectorLabel.setFocusCycleRoot(true);

    Mnemonics.setLocalizedText(
           repoSelectorLabel,
           NbBundle.getMessage(getClass(),
                               "QueryTopComponent.repoLabel.text"));//NOI18N

    setOpaque(false);

    newRepoButton.addFocusListener(this);
    repoSelector.addFocusListener(this);

    GroupLayout layout;
    setLayout(layout = new GroupLayout(this));
    layout.setHorizontalGroup(
            layout.createSequentialGroup()
                    .addComponent(repoSelectorLabel)
                    .addPreferredGap(RELATED)
                    .addComponent(repoSelector)
                    .addPreferredGap(RELATED)
                    .addComponent(newRepoButton));
    layout.setVerticalGroup(
            layout.createParallelGroup(BASELINE)
                    .addComponent(repoSelectorLabel)
                    .addComponent(repoSelector, DEFAULT_SIZE,
                                       DEFAULT_SIZE,
                                       PREFERRED_SIZE)
                    .addComponent(newRepoButton));
}
 
Example 3
Project: Logisim   File: DefaultRegistry.java   View Source Code Vote up 4 votes
public void registerDefaultButton(JComponent comp, JButton button) {
	comp.addFocusListener(new MyListener(button));
}