下面列出了javax.swing.JComponent#addFocusListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
@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);
}
/**
* <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);
}
}
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));
}
@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();
}
@Override
public void installUI(JComponent c) {
editor = (JTextComponent) c;
super.installUI(c);
c.setBorder(null);
c.setOpaque(false);
c.addFocusListener(focusListener);
editor.addPropertyChangeListener(iconListener);
}
@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();
}
/**
* <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);
}
/**
* <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);
}
/**
* <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);
}
/**
* 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();
}
/**
* 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();
}
});
}
});
}
@Override
public void installUI(JComponent button) {
super.installUI(button);
button.addFocusListener(FOCUS_LISTENER);
button.setForeground(style.getForeground());
button.setBorder(style.getBorder());
}
@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();
}
@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 );
}
public void registerDefaultButton(JComponent comp, JButton button) {
comp.addFocusListener(new MyListener(button));
}
/**
* 为组件添加焦点监听器(获得/取消焦点时可以自动设置/取消一个彩色的边框效果,以体高UI体验)
* 、右键菜单监听器(有复制/粘贴等功能).
*
* @param c the c
*/
public static void addOtherListener(JComponent c)
{
c.addFocusListener(FocusListenerImpl.getInstance());
// c.addMouseListener(new NLLookAndFeel.EditMenu());
}
/**
* 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();
}