java.awt.event.FocusEvent Java Examples
The following examples show how to use
java.awt.event.FocusEvent.
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: KeyboardFocusManager.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
static FocusEvent retargetUnexpectedFocusEvent(FocusEvent fe) { synchronized (heavyweightRequests) { // Any other case represents a failure condition which we did // not expect. We need to clearFocusRequestList() and patch up // the event as best as possible. if (removeFirstRequest()) { return (FocusEvent)retargetFocusEvent(fe); } Component source = fe.getComponent(); Component opposite = fe.getOppositeComponent(); boolean temporary = false; if (fe.getID() == FocusEvent.FOCUS_LOST && (opposite == null || isTemporary(opposite, source))) { temporary = true; } return new CausedFocusEvent(source, fe.getID(), temporary, opposite, CausedFocusEvent.Cause.NATIVE_SYSTEM); } }
Example #2
Source File: OptionsPageBuilder.java From ganttproject with GNU General Public License v3.0 | 6 votes |
public JComponent createGroupComponent(GPOptionGroup group) { GPOption<?>[] options = group.getOptions(); final JComponent optionsPanel = createGroupComponent(group, options); if (group.isTitled()) { UIUtil.createTitle(optionsPanel, myi18n.getOptionGroupLabel(group)); } JPanel result = new JPanel(new BorderLayout()); result.add(optionsPanel, BorderLayout.NORTH); result.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { optionsPanel.requestFocus(); } }); return result; }
Example #3
Source File: TableFocusManager.java From cuba with Apache License 2.0 | 6 votes |
public void processFocusEvent(FocusEvent e) { //TODO: CUBA 7 Rework TableFocusManager for Java 9 //https://github.com/cuba-platform/cuba/issues/893 // if (e.getID() == FocusEvent.FOCUS_GAINED) { // if (e instanceof CausedFocusEvent) { // if (((CausedFocusEvent) e).getCause() == CausedFocusEvent.Cause.TRAVERSAL_FORWARD) { // if (impl.getModel().getRowCount() > 0) { // // if focus from cell editor // if (e.getSource() == impl && impl.getSelectedRow() >= 0) { // int selectedColumn = impl.getSelectedColumn(); // focusTo(impl.getSelectedRow(), selectedColumn >= 0 ? selectedColumn : 0); // } else // moveToStart(0, 0); // } else // impl.transferFocus(); // // } else if (((CausedFocusEvent) e).getCause() == CausedFocusEvent.Cause.TRAVERSAL_BACKWARD) { // if (impl.getModel().getRowCount() > 0) { // moveToEnd(impl.getRowCount() - 1, impl.getColumnCount() - 1); // } else // impl.transferFocusBackward(); // } // } // } }
Example #4
Source File: KeyboardFocusManager.java From JDKSourceCode1.8 with MIT License | 6 votes |
static FocusEvent retargetUnexpectedFocusEvent(FocusEvent fe) { synchronized (heavyweightRequests) { // Any other case represents a failure condition which we did // not expect. We need to clearFocusRequestList() and patch up // the event as best as possible. if (removeFirstRequest()) { return (FocusEvent)retargetFocusEvent(fe); } Component source = fe.getComponent(); Component opposite = fe.getOppositeComponent(); boolean temporary = false; if (fe.getID() == FocusEvent.FOCUS_LOST && (opposite == null || isTemporary(opposite, source))) { temporary = true; } return new CausedFocusEvent(source, fe.getID(), temporary, opposite, CausedFocusEvent.Cause.NATIVE_SYSTEM); } }
Example #5
Source File: BaseTable.java From netbeans with Apache License 2.0 | 6 votes |
public void focusGained(FocusEvent fe) { Component c = fe.getOppositeComponent(); /* //handy for debugging System.out.println("Focus gained to " + (fe.getComponent().getName() == null ? fe.getComponent().getClass().getName() : fe.getComponent().getName()) + " temporary: " + fe.isTemporary() + " from " + (fe.getOppositeComponent() == null ? "null" : (fe.getOppositeComponent().getName() == null ? fe.getOppositeComponent().getClass().getName() : fe.getOppositeComponent().getName())) ); */ PropUtils.log(BaseTable.class, fe); if (!isKnownComponent(c)) { fireChange(); } if (!inEditRequest() && !inEditorRemoveRequest() && (fe.getComponent() == this)) { // System.out.println("Painting due to focus gain " + fe.getComponent()); // repaint(0,0,getWidth(),getHeight()); paintSelectionRow(); } }
Example #6
Source File: KeyboardFocusManager.java From Java8CN with Apache License 2.0 | 6 votes |
static FocusEvent retargetUnexpectedFocusEvent(FocusEvent fe) { synchronized (heavyweightRequests) { // Any other case represents a failure condition which we did // not expect. We need to clearFocusRequestList() and patch up // the event as best as possible. if (removeFirstRequest()) { return (FocusEvent)retargetFocusEvent(fe); } Component source = fe.getComponent(); Component opposite = fe.getOppositeComponent(); boolean temporary = false; if (fe.getID() == FocusEvent.FOCUS_LOST && (opposite == null || isTemporary(opposite, source))) { temporary = true; } return new CausedFocusEvent(source, fe.getID(), temporary, opposite, CausedFocusEvent.Cause.NATIVE_SYSTEM); } }
Example #7
Source File: JDayChooser.java From MeteoInfo with GNU Lesser General Public License v3.0 | 6 votes |
/** * JDayChooser is the FocusListener for all day buttons. (Added by Thomas * Schaefer) * * @param e * the FocusEvent */ /* * Code below commented out by Mark Brown on 24 Aug 2004. This code breaks * the JDateChooser code by triggering the actionPerformed method on the * next day button. This causes the date chosen to always be incremented by * one day. */ public void focusGained(FocusEvent e) { // JButton button = (JButton) e.getSource(); // String buttonText = button.getText(); // // if ((buttonText != null) && !buttonText.equals("") && // !e.isTemporary()) { // actionPerformed(new ActionEvent(e.getSource(), 0, null)); // } }
Example #8
Source File: LWTextFieldPeer.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
/** * Restoring native behavior. We should sets the selection range to zero, * when component lost its focus. * * @param e the focus event */ @Override void handleJavaFocusEvent(final FocusEvent e) { if (e.getID() == FocusEvent.FOCUS_LOST) { // In order to de-select the selection setCaretPosition(0); } super.handleJavaFocusEvent(e); }
Example #9
Source File: KeyboardFocusManagerPeerImpl.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("deprecation") public static boolean deliverFocus(Component lightweightChild, Component target, boolean temporary, boolean focusedWindowChangeAllowed, long time, CausedFocusEvent.Cause cause, Component currentFocusOwner) // provided by the descendant peers { if (lightweightChild == null) { lightweightChild = target; } Component currentOwner = currentFocusOwner; if (currentOwner != null && currentOwner.getPeer() == null) { currentOwner = null; } if (currentOwner != null) { FocusEvent fl = new CausedFocusEvent(currentOwner, FocusEvent.FOCUS_LOST, false, lightweightChild, cause); if (focusLog.isLoggable(PlatformLogger.Level.FINER)) { focusLog.finer("Posting focus event: " + fl); } SunToolkit.postEvent(SunToolkit.targetToAppContext(currentOwner), fl); } FocusEvent fg = new CausedFocusEvent(lightweightChild, FocusEvent.FOCUS_GAINED, false, currentOwner, cause); if (focusLog.isLoggable(PlatformLogger.Level.FINER)) { focusLog.finer("Posting focus event: " + fg); } SunToolkit.postEvent(SunToolkit.targetToAppContext(lightweightChild), fg); return true; }
Example #10
Source File: FormDateHandler.java From javamoney-examples with Apache License 2.0 | 5 votes |
public void focusLost(FocusEvent event) { JTextField field = (JTextField)event.getSource(); field.setText(UI_DATE_FORMAT.format(getDate(field))); }
Example #11
Source File: KeyboardFocusManagerPeerImpl.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
@Override public void clearGlobalFocusOwner(Window activeWindow) { if (activeWindow != null) { Component focusOwner = activeWindow.getFocusOwner(); if (focusLog.isLoggable(PlatformLogger.Level.FINE)) { focusLog.fine("Clearing global focus owner " + focusOwner); } if (focusOwner != null) { FocusEvent fl = new CausedFocusEvent(focusOwner, FocusEvent.FOCUS_LOST, false, null, CausedFocusEvent.Cause.CLEAR_GLOBAL_FOCUS_OWNER); SunToolkit.postPriorityEvent(fl); } } }
Example #12
Source File: ContainerFocusAutoTransferTest.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
public void init() { robot = Util.createRobot(); kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager(); Toolkit.getDefaultToolkit().addAWTEventListener(new AWTEventListener() { public void eventDispatched(AWTEvent event) { System.out.println("--> " + event); } }, FocusEvent.FOCUS_EVENT_MASK | WindowEvent.WINDOW_FOCUS_EVENT_MASK); }
Example #13
Source File: ButtonFactory.java From netbeans with Apache License 2.0 | 5 votes |
@Override protected void processFocusEvent(FocusEvent fe) { super.processFocusEvent(fe); if (fe.getID() == FocusEvent.FOCUS_LOST) { stopTimer(); } }
Example #14
Source File: ColorValueFormatter.java From darklaf with MIT License | 5 votes |
public void focusGained(final FocusEvent event) { Object source = event.getSource(); if (source instanceof JFormattedTextField) { this.text = (JFormattedTextField) source; SwingUtilities.invokeLater(() -> { if (this.text != null) { this.text.selectAll(); } }); } }
Example #15
Source File: XComponentPeer.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
/** * Called when component receives focus */ public void focusGained(FocusEvent e) { if (focusLog.isLoggable(PlatformLogger.Level.FINE)) { focusLog.fine("{0}", e); } bHasFocus = true; }
Example #16
Source File: DefaultValueAxisEditor.java From ECG-Viewer with GNU General Public License v2.0 | 5 votes |
/** * Revalidates minimum/maximum range. * * @param event the event. */ @Override public void focusLost(FocusEvent event) { if (event.getSource() == this.minimumRangeValue) { validateMinimum(); } else if (event.getSource() == this.maximumRangeValue) { validateMaximum(); } }
Example #17
Source File: GUIFrame.java From jaamsim with Apache License 2.0 | 5 votes |
private void addSnapToGridField(JToolBar buttonBar, Insets margin) { gridSpacing = new JTextField("1000000 m") { @Override protected void processFocusEvent(FocusEvent fe) { if (fe.getID() == FocusEvent.FOCUS_LOST) { GUIFrame.this.setSnapGridSpacing(this.getText().trim()); } else if (fe.getID() == FocusEvent.FOCUS_GAINED) { gridSpacing.selectAll(); } super.processFocusEvent( fe ); } }; gridSpacing.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { GUIFrame.this.setSnapGridSpacing(gridSpacing.getText().trim()); controlStartResume.requestFocusInWindow(); } }); gridSpacing.setMaximumSize(gridSpacing.getPreferredSize()); int hght = snapToGrid.getPreferredSize().height; gridSpacing.setPreferredSize(new Dimension(gridSpacing.getPreferredSize().width, hght)); gridSpacing.setHorizontalAlignment(JTextField.RIGHT); gridSpacing.setToolTipText(formatToolTip("Snap Grid Spacing", "Distance between adjacent grid points, e.g. 0.1 m, 10 km, etc.")); gridSpacing.setEnabled(snapToGrid.isSelected()); buttonBar.add(gridSpacing); }
Example #18
Source File: FileNameController.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void focusGained(FocusEvent e) { /* * Order of method calls hideInfo() and super.focusGained(e) is * important! See bug #113202. */ if (infoDisplayed) { hideInfo(); } super.focusGained(e); //selects all text }
Example #19
Source File: FlutterSettingsStep.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
@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); }
Example #20
Source File: URLPatternStep.java From netbeans with Apache License 2.0 | 5 votes |
public void focusGained(FocusEvent evt) { if(evt.getSource() == urlPatternPanel.depthComboBox && ! urlPatternPanel.useSubfolderRadioButton.isSelected()) { urlPatternPanel.useSubfolderRadioButton.setSelected(true); } }
Example #21
Source File: UrlComboBox.java From rest-client with Apache License 2.0 | 5 votes |
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); }
Example #22
Source File: MaterialFormattedTextField.java From swing-material with MIT License | 5 votes |
@Override protected void processFocusEvent(FocusEvent e) { super.processFocusEvent(e); floatingLabel.update(); line.update(); repaint(); }
Example #23
Source File: ControllerNameBoxItemListener.java From r2m-plugin-android with Apache License 2.0 | 5 votes |
@Override public void focusLost(FocusEvent focusEvent) { String controllerName = getControllerName(); if (controllerName == null) { return; } form.getControllerNameBox().getChildComponent().getEditor().setItem(controllerName); }
Example #24
Source File: GridNode.java From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 | 5 votes |
@Override public void focusGained(FocusEvent e) { if (e.getSource() instanceof JTextField) { JTextField tf = (JTextField) e.getSource(); if (!tf.getText().isEmpty()) { tf.setText(""); tf.setForeground(new Color(50, 50, 50)); } } }
Example #25
Source File: QueryController.java From netbeans with Apache License 2.0 | 5 votes |
@Override public void focusGained(FocusEvent e) { if(panel.changedFromTextField.getText().equals("")) { // NOI18N String lastChangeFrom = BugzillaConfig.getInstance().getLastChangeFrom(); panel.changedFromTextField.setText(lastChangeFrom); panel.changedFromTextField.setSelectionStart(0); panel.changedFromTextField.setSelectionEnd(lastChangeFrom.length()); } }
Example #26
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
private MainPanel() { super(new GridLayout(2, 1)); JTextField field = new JTextField("aaaaaaaaa"); field.addFocusListener(new FocusAdapter() { @Override public void focusGained(FocusEvent e) { ((JTextComponent) e.getComponent()).selectAll(); } }); add(makeTitledPanel("focusGained: selectAll", field)); add(makeTitledPanel("default", new JTextField("bbbbbbbbb"))); setBorder(BorderFactory.createEmptyBorder(10, 5, 10, 5)); setPreferredSize(new Dimension(320, 240)); }
Example #27
Source File: PageField.java From gcs with Mozilla Public License 2.0 | 5 votes |
@Override protected void processFocusEvent(FocusEvent event) { super.processFocusEvent(event); if (event.getID() == FocusEvent.FOCUS_GAINED) { selectAll(); } }
Example #28
Source File: ChangeMoveDialog.java From mylizzie with GNU General Public License v3.0 | 5 votes |
private void handleSpinnerMoveNumberEditorFocusGained(FocusEvent e) { Component component = e.getComponent(); if (component instanceof JTextComponent) { final JTextComponent textComponent = (JTextComponent) component; Lizzie.miscExecutor.schedule(() -> SwingUtilities.invokeLater(textComponent::selectAll), 250, TimeUnit.MILLISECONDS); } }
Example #29
Source File: WeakListener.java From netbeans with Apache License 2.0 | 5 votes |
/** Delegates to the original listener. */ public void focusGained(FocusEvent ev) { FocusListener l = (FocusListener) super.get(ev); if (l != null) { l.focusGained(ev); } }
Example #30
Source File: Input.java From 3DSoftwareRenderer with BSD 2-Clause "Simplified" License | 5 votes |
/** Updates state when the window loses focus */ public void focusLost(FocusEvent e) { for (int i = 0; i < keys.length; i++) keys[i] = false; for (int i = 0; i < mouseButtons.length; i++) mouseButtons[i] = false; }