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

The following examples show how to use javax.swing.JComponent#addFocusListener() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: pumpernickel   File: ColorWellUI.java    License: MIT License 6 votes vote down vote up
@Override
public void installUI(JComponent c) {
	c.addFocusListener(repaintFocusListener);
	c.addMouseListener(mouseListener);
	c.addMouseMotionListener(mouseListener);
	c.addKeyListener(keyListener);

	JColorWell well = (JColorWell) c;
	ColorChangeListener ccl = new ColorChangeListener(c);
	listenerMap.put(well, ccl);
	well.getColorSelectionModel().addChangeListener(ccl);

	ShowColorPaletteActionListener colorPaletteActionListener = new ShowColorPaletteActionListener();
	c.putClientProperty(DOUBLE_CLICK_ACTION_PROPERTY,
			colorPickerActionListener);
	c.putClientProperty(SPACE_KEY_ACTION_PROPERTY,
			colorPickerActionListener);
	c.putClientProperty(SINGLE_CLICK_ACTION_PROPERTY,
			colorPaletteActionListener);
	c.putClientProperty(DOWN_KEY_ACTION_PROPERTY,
			colorPaletteActionListener);
}
 
Example 2
Source Project: pumpernickel   File: PaletteUI.java    License: MIT License 6 votes vote down vote up
@Override
public void installUI(JComponent c) {
	super.installUI(c);
	c.addPropertyChangeListener(JPalette.PROPERTY_COLORS,
			propertyLayoutListener);
	c.addPropertyChangeListener(PaletteUI.PROPERTY_HIGHLIGHT,
			propertyRepaintListener);
	c.setLayout(new PaletteLayoutManager());
	c.setRequestFocusEnabled(true);
	c.addMouseListener(mouseListener);
	c.addFocusListener(focusListener);
	c.addKeyListener(keyListener);
	c.setFocusable(true);
	Fields fields = getFields((JPalette) c, true);
	fields.install();
	c.setBorder(new CompoundBorder(new LineBorder(new Color(0xB0B0B0)),
			new FocusedBorder(getDefaultBorder())));
	relayoutCells((JPalette) c);
}
 
Example 3
Source Project: littleluck   File: LuckComboBoxUI.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * <pre>
 * 初始化边框焦点监听器
 *
 * Initializes the border focus listener
 * <pre>
 *
 * @param c
 */
protected void installFocusListener(JComponent c)
{
    handle = new LuckComboboxFocusHandle();

    isFocusBorder = UIManager.getBoolean(LuckComboBoxUIBundle.ISFOCUSBORDER);

    if (isFocusBorder)
    {
        contentShape = new RoundRectangle2D.Float(0, 0, 0, 0, 8, 8);

        borderShape = new RoundRectangle2D.Float(0, 0, 0, 0, 8, 8);

        c.addMouseListener(handle);

        c.addFocusListener(handle);
    }
}
 
Example 4
Source Project: netbeans   File: RepoSelectorPanel.java    License: Apache License 2.0 5 votes vote down vote up
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 5
Source Project: pumpernickel   File: MultiThumbSliderUI.java    License: MIT License 5 votes vote down vote up
@Override
public void installUI(JComponent slider) {
	slider.addMouseListener(this);
	slider.addMouseMotionListener(this);
	slider.addFocusListener(focusListener);
	slider.addKeyListener(keyListener);
	slider.addComponentListener(compListener);
	slider.addPropertyChangeListener(propertyListener);
	slider.addPropertyChangeListener(THUMB_SHAPE_PROPERTY,
			thumbShapeListener);
	calculateGeometry();
}
 
Example 6
Source Project: pumpernickel   File: RoundTextFieldUI.java    License: MIT License 5 votes vote down vote up
@Override
public void installUI(JComponent c) {
	editor = (JTextComponent) c;
	super.installUI(c);
	c.setBorder(null);
	c.setOpaque(false);
	c.addFocusListener(focusListener);
	editor.addPropertyChangeListener(iconListener);
}
 
Example 7
Source Project: pumpernickel   File: SubtleScrollBarUI.java    License: MIT License 5 votes vote down vote up
@Override
public void installUI(JComponent c) {
	super.installUI(c);
	c.setOpaque(false);
	c.addPropertyChangeListener("opaque", opaqueListener);
	trackColor = new Color(trackColor.getRed(), trackColor.getGreen(),
			trackColor.getBlue(), 0);
	c.addPropertyChangeListener(PROPERTY_ROLLOVER_BOOLEAN, rolloverListener);
	c.addFocusListener(focusListener);
	refreshActive();
	refreshBorder();

}
 
Example 8
Source Project: littleluck   File: LuckPasswordFieldUI.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <pre>
 * 初始化边框焦点监听器
 *
 * Initializes the border focus listener
 * <pre>
 *
 * @param c
 */
protected void installFocusListener(JComponent c)
{
    handle = createFocusHandle();

    borderShape = new RoundRectangle2D.Float(0, 0, 0, 0, 8, 8);

    c.addMouseListener(handle);

    c.addFocusListener(handle);
}
 
Example 9
/**
 * <pre>
 * 初始化边框焦点监听器
 *
 * Initializes the border focus listener
 * <pre>
 *
 * @param c
 */
protected void installFocusListener(JComponent c)
{
    handle = createFocusHandle();

    borderShape = new RoundRectangle2D.Float(0, 0, 0, 0, 8, 8);

    c.addMouseListener(handle);

    c.addFocusListener(handle);
}
 
Example 10
Source Project: littleluck   File: LuckTexFieldUI.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <pre>
 * 初始化边框焦点监听器
 *
 * Initializes the border focus listener
 * <pre>
 *
 * @param c
 */
protected void installFocusListener(JComponent c)
{
    handle = createFocusHandle();

    borderShape = new RoundRectangle2D.Float(0, 0, 0, 0, 8, 8);

    c.addMouseListener(handle);

    c.addFocusListener(handle);
}
 
Example 11
Source Project: beautyeye   File: BEPasswordFieldUI.java    License: Apache License 2.0 5 votes vote down vote up
/**
     * Creates a UI for a JPasswordField.
     *
     * @param c the password field
     * @return the UI
     */
    public static ComponentUI createUI(JComponent c) 
    {
    	c.addFocusListener(FocusListenerImpl.getInstance());
//    	c.addMouseListener(new NLLookAndFeel.EditMenu());
        return new BEPasswordFieldUI();
    }
 
Example 12
/**
 * Create a new DropAmountChooser.
 *
 * @param item the item whose drop should be handled by the DropAmountChooser
 * @param target target where the item should be dropped if the user chooses
 * 	an amount greater than 0
 * @param point drop location
 */
DropAmountChooser(StackableItem item, DropTarget target, Point point) {
	this.item = item;
	this.target = target;
	location = point;
	popup = createPopup();

	/*
	 * Select the text when the the popup is displayed. Unfortunately the
	 * selection is normally cleared when the text field gets focus, so we
	 * need to do it in a focus listener. Also the focus listener gets run
	 * before the selection is cleared so to get the desired effect the
	 * selection needs to be pushed to the event queue.
	 */
	final JComponent field = getTextField();
	field.addFocusListener(new FocusAdapter() {
		@Override
		public void focusGained(FocusEvent e) {
			SwingUtilities.invokeLater(new Runnable() {
				@Override
				public void run() {
					((JTextComponent) field).selectAll();
				}
			});
		}
	});
}
 
Example 13
@Override
public void installUI(JComponent button) {
	super.installUI(button);
	button.addFocusListener(FOCUS_LISTENER);
	button.setForeground(style.getForeground());
	button.setBorder(style.getBorder());
}
 
Example 14
@Override
public void installUI(JComponent slider) {
	slider.addMouseListener(this);
	slider.addMouseMotionListener(this);
	slider.addFocusListener(focusListener);
	slider.addKeyListener(keyListener);
	slider.addComponentListener(compListener);
	slider.addPropertyChangeListener(propertyListener);
	slider.addPropertyChangeListener(THUMB_SHAPE_PROPERTY, thumbShapeListener);
	calculateGeometry();
}
 
Example 15
Source Project: birt   File: SwingRendererImpl.java    License: Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void setProperty( String sProperty, Object oValue )
{
	// InteractiveRenderer(iv) is only for Swing
	if ( sProperty.equals( IDeviceRenderer.UPDATE_NOTIFIER ) && iv != null )
	{
		_iun = (IUpdateNotifier) oValue;
		iv.setUpdateNotifier( _iun );
		_lhmAllTriggers.clear( );
		Object obj = _iun.peerInstance( );

		if ( obj instanceof JComponent )
		{
			JComponent jc = (JComponent) obj;

			if ( _eh != null )
			{
				// We can't promise to remove all the old swtEventHandler
				// due to SWT limitation here, so be sure to just attach the
				// update_notifier only to one renderer.

				jc.removeMouseListener( _eh );
				jc.removeMouseMotionListener( _eh );
				jc.removeKeyListener( _eh );
				jc.removeFocusListener( _eh );
			}

			_eh = new SwingEventHandler( iv,
					_lhmAllTriggers,
					_iun,
					getULocale( ) );
			jc.addMouseListener( _eh );
			jc.addMouseMotionListener( _eh );
			jc.addKeyListener( _eh );
			jc.addFocusListener( _eh );
		}
	}
	
	super.setProperty( sProperty, oValue );
}
 
Example 16
public void registerDefaultButton(JComponent comp, JButton button) {
	comp.addFocusListener(new MyListener(button));
}
 
Example 17
Source Project: beautyeye   File: BETextFieldUI.java    License: Apache License 2.0 2 votes vote down vote up
/**
     * 为组件添加焦点监听器(获得/取消焦点时可以自动设置/取消一个彩色的边框效果,以体高UI体验)
     * 、右键菜单监听器(有复制/粘贴等功能).
     *
     * @param c the c
     */
    public static void addOtherListener(JComponent c)
    {
    	c.addFocusListener(FocusListenerImpl.getInstance());
//    	c.addMouseListener(new NLLookAndFeel.EditMenu());
    }
 
Example 18
/**
 * Creates a UI for a JPasswordField.
 *
 * @param c the password field
 * @return the UI
 */
public static ComponentUI createUI(JComponent c) 
{
	c.addFocusListener(FocusListenerImpl.getInstance());
    return new BEFormattedTextFieldUI();
}