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

The following examples show how to use javax.swing.JComponent#addFocusListener() . 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 File: ColorWellUI.java    From pumpernickel with 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 File: PaletteUI.java    From pumpernickel with 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 File: LuckComboBoxUI.java    From littleluck with 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 File: LuckTexFieldUI.java    From littleluck with 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 5
Source File: SwingRendererImpl.java    From birt with 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 6
Source File: MultiThumbSliderUI.java    From PyramidShader with GNU General Public License v3.0 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 7
Source File: StyledButtonUI.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void installUI(JComponent button) {
	super.installUI(button);
	button.addFocusListener(FOCUS_LISTENER);
	button.setForeground(style.getForeground());
	button.setBorder(style.getBorder());
}
 
Example 8
Source File: DropAmountChooser.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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 9
Source File: BEPasswordFieldUI.java    From beautyeye with 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 10
Source File: RepoSelectorPanel.java    From netbeans with 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 11
Source File: LuckFormattedTextFieldUI.java    From littleluck with 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 12
Source File: LuckPasswordFieldUI.java    From littleluck with 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 13
Source File: SubtleScrollBarUI.java    From pumpernickel with 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 14
Source File: RoundTextFieldUI.java    From pumpernickel with 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 15
Source File: MultiThumbSliderUI.java    From pumpernickel with 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 16
Source File: DefaultRegistry.java    From Logisim with GNU General Public License v3.0 4 votes vote down vote up
public void registerDefaultButton(JComponent comp, JButton button) {
	comp.addFocusListener(new MyListener(button));
}
 
Example 17
Source File: BETextFieldUI.java    From beautyeye with 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
Source File: BEFormattedTextFieldUI.java    From beautyeye with Apache License 2.0 2 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());
    return new BEFormattedTextFieldUI();
}