Java源码示例:java.awt.event.FocusAdapter
示例1
protected JComponent createFileNamePanel(final JFileChooser fileChooser) {
JPanel fileNamePanel = new JPanel();
fileNamePanel.setLayout(new BoxLayout(fileNamePanel, BoxLayout.LINE_AXIS));
fileNameLabel = new AlignedLabel();
populateFileNameLabel();
fileNamePanel.add(fileNameLabel);
fileNameTextField = new FileTextField();
fileNamePanel.add(fileNameTextField);
fileNameLabel.setLabelFor(fileNameTextField);
fileNameTextField.addFocusListener(new FocusAdapter() {
public void focusGained(final FocusEvent e) {
if (!getFileChooser().isMultiSelectionEnabled()) {
filePane.clearSelection();
}
}
});
if (fileChooser.isMultiSelectionEnabled()) {
setFileName(fileNameString(fileChooser.getSelectedFiles()));
} else {
setFileName(fileNameString(fileChooser.getSelectedFile()));
}
return fileNamePanel;
}
示例2
/** 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
/** 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();
}
示例4
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");
}
示例5
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");
}
示例6
public TextActionCellEditor() {
leftButton.setFocusable(false);
leftButton.setVisible(false);
leftButton.setMargin(PropertyHelper.BUTTON_INSETS);
text.setFocusable(true);
text.setBorder(GuiUtils.getTableCellBorder());
text.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
if (!e.isTemporary()) {
stopCellEditing();
}
}
});
rightButton.setFocusable(false);
rightButton.setVisible(false);
rightButton.setMargin(PropertyHelper.BUTTON_INSETS);
panel.add(leftButton, BorderLayout.WEST);
panel.add(text, BorderLayout.CENTER);
panel.add(rightButton, BorderLayout.EAST);
panel.setFocusable(false);
}
示例7
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"));
}
});
}
示例8
/**
* Add popup with suggestion to text component
* @param textComponent text component
* @param suggestionSource source of suggestions
* @param suggestionRenderer renderer for suggestions
* @param selectionListener suggestion listener to be executed after suggestion is selected
* @param clearFocusAfterSelection true if text selection should be removed and caret set to end of text after selecting suggestion
* @param <T> Suggestion type
*/
public static <T> void decorate(final JTextComponent textComponent,
SuggestionSource<T> suggestionSource,
SuggestionRenderer<T> suggestionRenderer,
SelectionListener<T> selectionListener,
boolean clearFocusAfterSelection) {
Document document = textComponent.getDocument();
SuggestionDocumentListener<? extends T> listener = new SuggestionDocumentListener<>(textComponent, suggestionSource, suggestionRenderer, selectionListener);
document.addDocumentListener(listener);
if (clearFocusAfterSelection) {
textComponent.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
//do not select all on OSX after suggestion is selected
if (e.getOppositeComponent() == null) {
clearTextFieldSelectionAsync(textComponent);
}
}
});
}
}
示例9
private static Runnable createOnFocusGained(final JTextComponent textComponent, final Runnable onFocusGained) {
final FocusListener focusListener = new FocusAdapter() {
@Override
public void focusGained(FocusEvent arg0) {
super.focusGained(arg0);
SwingUtilities.invokeLater(onFocusGained);
textComponent.removeFocusListener(this);
}
};
textComponent.addFocusListener(focusListener);
return new Runnable() {
@Override
public void run() {
textComponent.requestFocus();
}
};
}
示例10
void attachOnFocusLost(final ActionListener onSuccess) {
myTextEditor.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
try {
tryCommit();
onSuccess.actionPerformed(new ActionEvent(myDatePicker, ActionEvent.ACTION_PERFORMED, ""));
return;
} catch (ValidationException | ParseException ex) {
// We probably don't want to log parse/validation exceptions
// If user input is not valid we reset value to the initial one
resetValue();
}
}
});
}
示例11
public LayerNameEditor(LayerButton layerButton) {
super(layerButton.getLayer().getName());
// TODO setting up a tool tip would show an
// annoying GRAY "disabled tooltip"
// One solution would be to put
// UIManager.put("ToolTip[Disabled].backgroundPainter", UIManager.get("ToolTip[Enabled].backgroundPainter"));
// at the beginning (not ideal), another would be
// to create a custom tooltip specifically
// for this component
// setToolTipText("Double-click to rename this layer.");
this.layerButton = layerButton;
disableEditing();
addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
finishEditing();
}
});
// disable if enter pressed
addActionListener(e -> finishEditing());
}
示例12
private void init() {
if ( dateChooserPanel == null ) {
dateChooserPanel = new DateChooserPanel( Calendar.getInstance(), true );
dateChooserPanel.addPropertyChangeListener( DateChooserPanel.PROPERTY_DATE, new InternalDateUpdateHandler() );
dateField.addPropertyChangeListener( "value", new PropertyChangeListener() {
public void propertyChange( final PropertyChangeEvent evt ) {
Date newValue = (Date) evt.getNewValue();
newValue = newValue == null ? null : DateConverter.convertToDateType( newValue, dateType );
dateChooserPanel.setDate( newValue, false );
dateChooserPanel.setDateSelected( true );
}
} );
dateField.addFocusListener( new FocusAdapter() {
public void focusGained( final FocusEvent e ) {
dateChooserPanel.setDateSelected( false );
}
} );
if ( dateField.getFormatterFactory() == null ) {
setDateFormat( createDateFormat( DEFAULT_FORMAT, Locale.getDefault(), TimeZone.getDefault() ) );
}
}
}
示例13
TComp(@Nonnull DesktopEditorWindow window, @Nonnull DesktopEditorWithProviderComposite 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(() -> {
if (!hasFocus()) return;
final JComponent focus = myEditor.getSelectedEditorWithProvider().getFileEditor().getPreferredFocusedComponent();
if (focus != null && !focus.hasFocus()) {
IdeFocusManager.getGlobalInstance().requestFocus(focus, true);
}
});
}
});
}
示例14
private FocusAdapter buildFocusAdapter(Consumer<FocusEvent> focusLostConsumer)
{
return new FocusAdapter()
{
@Override
public void focusLost(FocusEvent e)
{
focusLostConsumer.accept(e);
}
};
}
示例15
@Override
public void installListeners() {
this.focusListener = new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
SwingUtilities.invokeLater(() -> {
if (WidgetUtilities.hasTextFocusSelectAllProperty(jcomp)
&& jcomp.isEditable())
jcomp.selectAll();
});
}
};
this.jcomp.addFocusListener(this.focusListener);
}
示例16
private void initComponentsMore() {
contentPanel.setLayout(new GridBagLayout());
contentPanel.setBackground(UIManager.getColor("Table.background")); //NOI18N
int row = 0;
combos = new ArrayList<>(items.size());
Font monoSpaced = new Font("Monospaced", Font.PLAIN, new JLabel().getFont().getSize()); //NOI18N
FocusListener focusListener = new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
Component c = e.getComponent();
Rectangle r = c.getBounds();
contentPanel.scrollRectToVisible(r);
}
};
for (int i = 0; i < items.size(); i++) {
ResolveDeclarationItem item = items.get(i);
JComboBox jComboBox = createComboBox(item, monoSpaced, focusListener);
combos.add(jComboBox);
JLabel lblSimpleName = new JLabel(item.getName());
lblSimpleName.setOpaque(false);
lblSimpleName.setFont(monoSpaced);
lblSimpleName.setLabelFor(jComboBox);
contentPanel.add(lblSimpleName, new GridBagConstraints(0, row, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(3, 5, 2, 5), 0, 0));
contentPanel.add(jComboBox, new GridBagConstraints(1, row++, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(3, 5, 2, 5), 0, 0));
}
contentPanel.add(new JLabel(), new GridBagConstraints(2, row, 2, 1, 0.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
Dimension d = contentPanel.getPreferredSize();
d.height = getRowHeight() * Math.min(combos.size(), 6);
}
示例17
public DFrame(final Control control) {
super(new BorderLayout());
setFocusable(true);
setFocusCycleRoot(true);
this.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
control.focusGained(DFrame.this);
}
});
control.addDFrame(this);
}
示例18
public IndependenceSwingTest() {
frame = new JFrame();
frame.setSize(200, 200);
// This textfield will be used to update the contents of clipboards
tf1 = new JTextField();
tf1.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent fe) {
tf1.setText("Clipboards_Independance_Testing");
}
});
// TextFields to get the contents of clipboard
tf2 = new JTextField();
tf3 = new JTextField();
panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(tf2, BorderLayout.NORTH);
panel.add(tf3, BorderLayout.SOUTH);
frame.add(tf1, BorderLayout.NORTH);
frame.add(panel, BorderLayout.CENTER);
frame.setVisible(true);
tf1.requestFocus();
}
示例19
public GenericCellEditor() {
textField = new JTextField();
textField.setFocusable(true);
textField.setBorder(GuiUtils.getTableCellBorder());
textField.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
if (!e.isTemporary()) {
stopCellEditing();
}
}
});
}
示例20
@Override
protected void onWizardStarting(@NotNull ModelWizard.Facade wizard) {
FlutterProjectModel model = getModel();
myKotlinCheckBox.setText(FlutterBundle.message("module.wizard.language.name_kotlin"));
mySwiftCheckBox.setText(FlutterBundle.message("module.wizard.language.name_swift"));
myBindings.bindTwoWay(new SelectedProperty(myUseAndroidxCheckBox), getModel().useAndroidX());
TextProperty packageNameText = new TextProperty(myPackageName);
Expression<String> computedPackageName = new DomainToPackageExpression(model.companyDomain(), model.projectName()) {
@Override
public String get() {
return super.get().replaceAll("_", "");
}
};
BoolProperty isPackageSynced = new BoolValueProperty(true);
myBindings.bind(packageNameText, computedPackageName, isPackageSynced);
myBindings.bind(model.packageName(), packageNameText);
myListeners.listen(packageNameText, value -> isPackageSynced.set(value.equals(computedPackageName.get())));
// The wizard changed substantially in 3.5. Something causes this page to not get properly validated
// after it is added to the Swing tree. Here we check that we have to validate the tree, then do so.
// It only needs to be done once, so we remove the listener to prevent possible flicker.
focusListener = new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
super.focusGained(e);
Container parent = myRoot;
while (parent != null && !(parent instanceof JBLayeredPane)) {
parent = parent.getParent();
}
if (parent != null) {
parent.validate();
}
myPackageName.removeFocusListener(focusListener);
}
};
myPackageName.addFocusListener(focusListener);
}
示例21
private FocusAdapter buildFocusAdapter(Consumer<FocusEvent> focusLostConsumer)
{
return new FocusAdapter()
{
@Override
public void focusLost(FocusEvent e)
{
focusLostConsumer.accept(e);
}
};
}
示例22
/**
* Creates an uneditable JTextField with the given text
*
* @param text
* The content of the JTextField
* @return
*/
private static JTextField makeTextField(String text) {
JTextField urlField = new JTextField(text);
urlField.setEditable(false);
urlField.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(java.awt.event.FocusEvent evt) {
urlField.getCaret().setVisible(true);
urlField.selectAll();
}
});
return urlField;
}
示例23
private void initComponents() {
myEnvironmentForm = new MavenEnvironmentForm();
Project project = myProjectOrNull == null ? ProjectManager.getInstance().getDefaultProject() : myProjectOrNull;
myEnvironmentForm.getData(MavenProjectsManager.getInstance(project).getGeneralSettings().clone());
myEnvironmentPanel.add(myEnvironmentForm.createComponent(), BorderLayout.CENTER);
//AS TODO: If we keep on using the archetype properties we might add a description to the Required Properties
//AS TODO: but then we need to copy this class over and add the description to the dialog.
myMavenPropertiesPanel = new MavenPropertiesPanel(myAvailableProperties);
myPropertiesPanel.add(myMavenPropertiesPanel);
doFillIn.setSelected(true);
artifactName.addKeyListener(
new KeyAdapter() {
@Override
public void keyReleased(KeyEvent keyEvent) {
super.keyReleased(keyEvent);
if(doFillIn.isSelected()) {
updateProperties();
}
}
}
);
artifactName.addFocusListener(
new FocusAdapter() {
@Override
public void focusLost(FocusEvent focusEvent) {
super.focusLost(focusEvent);
if(doFillIn.isSelected()) {
updateProperties();
}
}
}
);
}
示例24
public JFXPanelEx(){
addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
hidePopUps();
}
});
}
示例25
private void setupChatEntry() {
final KeyListener tabcompletion = new ChatCompletionHelper(chatText,
World.get().getPlayerList().getNamesList(),
SlashActionRepository.getCommandNames());
chatText.addKeyListener(tabcompletion);
/*
* Always redirect focus to chat field
*/
screen.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(final FocusEvent e) {
chatText.getPlayerChatText().requestFocus();
}
});
}
示例26
public JComponent createGroupComponent(GPOptionGroup group, GPOption<?>... options) {
JPanel optionsPanel = new JPanel();
int hasUiCount = 0;
for (int i = 0; i < options.length; i++) {
GPOption<?> nextOption = options[i];
if (!nextOption.hasUi()) {
continue;
}
hasUiCount++;
final Component nextComponent = createOptionComponent(group, nextOption);
if (needsLabel(group, nextOption)) {
Component nextLabel = createOptionLabel(group, options[i]);
optionsPanel.add(nextLabel);
optionsPanel.add(nextComponent);
} else {
optionsPanel.add(nextComponent);
optionsPanel.add(new JPanel());
}
if (i == 0) {
optionsPanel.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
super.focusGained(e);
nextComponent.requestFocus();
}
});
}
}
if (hasUiCount > 0) {
myLayoutApi.layout(optionsPanel, hasUiCount);
}
return optionsPanel;
}
示例27
public UrlComboBox() {
setToolTipText("URL");
setEditable(true);
final JTextField editorComponent = (JTextField) getEditor().getEditorComponent();
editorComponent.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
editorComponent.selectAll();
}
});
AutoCompletion ac = new AutoCompletion(this);
ac.setStrict(false);
ac.setStrictCompletion(false);
}
示例28
protected TabTitleEditListener(JTabbedPane tabbedPane) {
super();
this.tabbedPane = tabbedPane;
editor.setBorder(BorderFactory.createEmptyBorder());
editor.addFocusListener(new FocusAdapter() {
@Override public void focusLost(FocusEvent e) {
renameTabTitle.actionPerformed(new ActionEvent(tabbedPane, ActionEvent.ACTION_PERFORMED, RENAME));
}
});
InputMap im = editor.getInputMap(JComponent.WHEN_FOCUSED);
ActionMap am = editor.getActionMap();
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CANCEL);
am.put(CANCEL, cancelEditing);
im.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), RENAME);
am.put(RENAME, renameTabTitle);
editor.getDocument().addDocumentListener(this);
// editor.addKeyListener(new KeyAdapter() {
// @Override public void keyPressed(KeyEvent e) {
// if (e.getKeyCode() == KeyEvent.VK_ENTER) {
// renameTabTitle();
// } else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
// cancelEditing();
// } else {
// editor.setPreferredSize(editor.getText().length() > len ? null : dim);
// tabbedPane.revalidate();
// }
// }
// });
tabbedPane.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), START);
tabbedPane.getActionMap().put(START, startEditing);
}
示例29
@Override
public void addChangeListener(final ChangeListener l) {
final GenericTagEditor t = this;
editor.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
l.change(t);
}
});
}
示例30
@Override
public void addChangeListener(final ChangeListener l) {
final GenericTagEditor t = this;
addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
l.change(t);
}
});
}