本文整理汇总了Java中java.awt.event.FocusAdapter类的典型用法代码示例。如果您正苦于以下问题:Java FocusAdapter类的具体用法?Java FocusAdapter怎么用?Java FocusAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FocusAdapter类属于java.awt.event包,在下文中一共展示了FocusAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: EditorUI
import java.awt.event.FocusAdapter; //导入依赖的package包/类
/** Construct extended UI for the use with a text component */
public EditorUI() {
focusL = new FocusAdapter() {
public @Override void focusGained(FocusEvent evt) {
/* Fix of #25475 - copyAction's enabled flag
* must be updated on focus change
*/
stateChanged(null);
if (component!=null){
BaseTextUI ui = (BaseTextUI)component.getUI();
if (ui!=null) ui.refresh();
}
}
@Override
public void focusLost(FocusEvent e) {
// see #222935, update actions before menu activates
if (e.isTemporary()) {
doStateChange(true);
}
}
};
getToolTipSupport();
}
示例2: SpecialkeyPanel
import java.awt.event.FocusAdapter; //导入依赖的package包/类
/** Creates new form SpecialkeyPanel */
public SpecialkeyPanel(final Popupable parent, JTextField target) {
this.parent = parent;
this.target = target;
initComponents();
target.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
parent.hidePopup();
}
});
downButton.addActionListener(this);
enterButton.addActionListener(this);
escButton.addActionListener(this);
leftButton.addActionListener(this);
rightButton.addActionListener(this);
tabButton.addActionListener(this);
upButton.addActionListener(this);
wheelUpButton.addActionListener(this);
wheelDownButton.addActionListener(this);
}
示例3: GenerateCodePanel
import java.awt.event.FocusAdapter; //导入依赖的package包/类
/** Creates new form GenerateCodePanel */
public GenerateCodePanel(JTextComponent component, List<? extends CodeGenerator> generators) {
this.component = component;
initComponents();
setFocusable(false);
setNextFocusableComponent(jList1);
setBackground(jList1.getBackground());
jScrollPane1.setBackground(jList1.getBackground());
jList1.setModel(createModel(generators));
jList1.setSelectedIndex(0);
jList1.setVisibleRowCount(generators.size() > 16 ? 16 : generators.size());
jList1.setCellRenderer(new Renderer(jList1));
jList1.grabFocus();
jList1.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
PopupUtil.hidePopup();
}
});
}
示例4: AutoCompletionComboBox
import java.awt.event.FocusAdapter; //导入依赖的package包/类
public AutoCompletionComboBox(boolean caseSensitive, int preferredWidth, int preferredHeight, boolean wide,
ComboBoxModel model) {
super(preferredWidth, preferredHeight, wide, model);
this.caseSensitive = caseSensitive;
setEditable(true);
setEditor(getEditor());
addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
setSelectedItem(((JTextField) getEditor().getEditorComponent()).getText());
actionPerformed(new ActionEvent(this, 0, "editingStopped"));
}
});
}
示例5: SystemSelectionAWTTest
import java.awt.event.FocusAdapter; //导入依赖的package包/类
SystemSelectionAWTTest() {
frame = new Frame();
frame.setSize(200, 200);
tf1 = new TextField();
tf1.addFocusListener( new FocusAdapter() {
public void focusGained(FocusEvent fe) {
fe.getSource();
}
});
tf2 = new TextField();
frame.add(tf2, BorderLayout.NORTH);
frame.add(tf1, BorderLayout.CENTER);
frame.setVisible(true);
frame.toFront();
tf1.requestFocus();
tf1.setText("Selection Testing");
}
示例6: SystemSelectionSwingTest
import java.awt.event.FocusAdapter; //导入依赖的package包/类
SystemSelectionSwingTest() {
jframe = new JFrame();
jframe.setSize(200, 200);
jtf1 = new JTextField();
jtf1.addFocusListener( new FocusAdapter() {
public void focusGained(FocusEvent fe) {
fe.getSource();
}
});
jtf2 = new JTextField();
jframe.add(jtf2, BorderLayout.NORTH);
jframe.add(jtf1, BorderLayout.CENTER);
jframe.setVisible(true);
jframe.toFront();
jtf1.requestFocus();
jtf1.setText("Selection Testing");
}
示例7: addListeners
import java.awt.event.FocusAdapter; //导入依赖的package包/类
public void addListeners( final TextBox textBox ) {
final MovingMan.Listener listener = new MovingMan.Listener() {
public void changed() {
textBox.setText( decimalFormat.format( model.getMovingMan().getPosition() ) );
}
};
listener.changed();//synchronize state on initialization
model.getMovingMan().addListener( listener );
textBox.addListener( new TextBox.Listener() {
public void changed() {
String text = textBox.getText();//have to store it since the next line modifies it
model.getMovingMan().setPositionDriven();
model.setMousePosition( Double.parseDouble( text ) );
}
} );
textBox.addFocusListener( new FocusAdapter() {
public void focusGained( FocusEvent e ) {
model.getMovingMan().setPositionDriven();
}
} );
}
示例8: TargetTextArea
import java.awt.event.FocusAdapter; //导入依赖的package包/类
public TargetTextArea( String key, String value ) {
super( value );
this.key = key;
this.savedValue = value;
setEditable( true );
// tab or shift-tab will move you to the next or previous text field
getInputMap( JComponent.WHEN_FOCUSED ).put( KeyStroke.getKeyStroke( "TAB" ), NEXT_FOCUS_ACTION.getValue( Action.NAME ) );
getInputMap( JComponent.WHEN_FOCUSED ).put( KeyStroke.getKeyStroke( "shift TAB" ), PREVIOUS_FOCUS_ACTION.getValue( Action.NAME ) );
getActionMap().put( NEXT_FOCUS_ACTION.getValue( Action.NAME ), NEXT_FOCUS_ACTION );
getActionMap().put( PREVIOUS_FOCUS_ACTION.getValue( Action.NAME ), PREVIOUS_FOCUS_ACTION );
// ensure that the text field is visible when doing tab traversal
addFocusListener( new FocusAdapter() {
public void focusGained( FocusEvent e ) {
TargetTextArea.this.scrollRectToVisible( TargetTextArea.this.getBounds() );
}
});
}
示例9: LayerNameEditor
import java.awt.event.FocusAdapter; //导入依赖的package包/类
public LayerNameEditor(LayerButton layerButton, Layer layer) {
super(layer.getName());
this.layerButton = layerButton;
disableEditing();
addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
disableEditing();
layer.setName(getText(), AddToHistory.YES);
}
});
// disable if enter pressed
addActionListener(e -> {
disableEditing();
layer.setName(getText(), AddToHistory.YES);
});
}
示例10: GoToHexPanel
import java.awt.event.FocusAdapter; //导入依赖的package包/类
public GoToHexPanel() {
initComponents();
// Spinner selection workaround from http://forums.sun.com/thread.jspa?threadID=409748&forumID=57
((JSpinner.DefaultEditor) positionSpinner.getEditor()).getTextField().addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
if (e.getSource() instanceof JTextComponent) {
final JTextComponent textComponent = ((JTextComponent) e.getSource());
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
textComponent.selectAll();
}
});
}
}
});
}
示例11: CopyableLabel
import java.awt.event.FocusAdapter; //导入依赖的package包/类
private CopyableLabel(@NotNull String text) {
addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
int caretPosition = getCaretPosition();
setSelectionStart(caretPosition);
setSelectionEnd(caretPosition);
}
});
setWrapStyleWord(false);
setFont(UIUtil.getLabelFont());
setEditable(false);
setForeground(UIUtil.getLabelForeground());
setBackground(UIUtil.TRANSPARENT_COLOR);
setBorder(null);
setOpaque(false);
setText(StringUtil.stripHtml(text, false));
setCaretPosition(0);
UIUtil.putClientProperty(this, UIUtil.NOT_IN_HIERARCHY_COMPONENTS, Collections.singleton(ELLIPSIS_LABEL));
}
示例12: TComp
import java.awt.event.FocusAdapter; //导入依赖的package包/类
TComp(@NotNull EditorWindow window, @NotNull EditorWithProviderComposite editor) {
super(new BorderLayout());
myEditor = editor;
myWindow = window;
add(editor.getComponent(), BorderLayout.CENTER);
addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
if (!TComp.this.hasFocus()) return;
final JComponent focus = myEditor.getSelectedEditorWithProvider().getFirst().getPreferredFocusedComponent();
if (focus != null && !focus.hasFocus()) {
IdeFocusManager.getGlobalInstance().requestFocus(focus, true);
}
}
});
}
});
}
示例13: createSignaturePanel
import java.awt.event.FocusAdapter; //导入依赖的package包/类
private JComponent createSignaturePanel() {
mySignatureArea = createSignaturePreviewComponent();
JPanel panel = new JPanel(new BorderLayout());
panel.add(SeparatorFactory.createSeparator(RefactoringBundle.message("signature.preview.border.title"), null), BorderLayout.NORTH);
panel.add(mySignatureArea, BorderLayout.CENTER);
mySignatureArea.setPreferredSize(new Dimension(-1, 130));
mySignatureArea.setMinimumSize(new Dimension(-1, 130));
mySignatureArea.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
Container root = findTraversalRoot(getContentPane());
if (root != null) {
Component c = root.getFocusTraversalPolicy().getComponentAfter(root, mySignatureArea);
if (c != null) {
IdeFocusManager.findInstance().requestFocus(c, true);
}
}
}
});
updateSignature();
return panel;
}
示例14: AutoCompletionComboBox
import java.awt.event.FocusAdapter; //导入依赖的package包/类
public AutoCompletionComboBox(boolean caseSensitive, int preferredWidth, int preferredHeight, boolean wide,
ComboBoxModel<E> model) {
super(preferredWidth, preferredHeight, wide, model);
this.caseSensitive = caseSensitive;
setEditable(true);
setEditor(getEditor());
addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
setSelectedItem(((JTextField) getEditor().getEditorComponent()).getText());
actionPerformed(new ActionEvent(this, 0, "editingStopped"));
}
});
}
示例15: ComboButton
import java.awt.event.FocusAdapter; //导入依赖的package包/类
public ComboButton(IWidget context, ContextPaletteButtonModel desc) {
setContext(context);
setModel(desc);
setLayout(new BorderLayout());
setBackground(ContextPalette.BACKGROUND);
setExpanded(false);
addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
// setExpanded(false);
}
});
InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), "LeftAction");
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), "RightAction");
getActionMap().put("LeftAction", new LeftMoveButtonAction());
getActionMap().put("RightAction", new RightMoveButtonAction());
}