java.awt.event.FocusAdapter Java Examples

The following examples show how to use java.awt.event.FocusAdapter. 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: DarkFileChooserUI.java    From darklaf with MIT License 6 votes vote down vote up
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;
}
 
Example #2
Source File: TextActionCellEditor.java    From workcraft with MIT License 6 votes vote down vote up
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);
}
 
Example #3
Source File: TreeTableCellEditorImpl.java    From ganttproject with GNU General Public License v3.0 6 votes vote down vote up
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();
    }
  };
}
 
Example #4
Source File: SystemSelectionSwingTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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");
}
 
Example #5
Source File: SystemSelectionAWTTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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");
}
 
Example #6
Source File: DateCellEditor.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
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() ) );
    }
  }
}
 
Example #7
Source File: LayerNameEditor.java    From Pixelitor with GNU General Public License v3.0 6 votes vote down vote up
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());
}
 
Example #8
Source File: UIUtil.java    From ganttproject with GNU General Public License v3.0 6 votes vote down vote up
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();
      }
    }
  });
}
 
Example #9
Source File: SuggestDecorator.java    From otroslogviewer with Apache License 2.0 6 votes vote down vote up
/**
 * 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);
        }
      }
    });
  }
}
 
Example #10
Source File: EditorUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** 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();
}
 
Example #11
Source File: DesktopEditorWindow.java    From consulo with Apache License 2.0 6 votes vote down vote up
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);
        }
      });
    }
  });
}
 
Example #12
Source File: AutoCompletionComboBox.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
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"));
		}
	});
}
 
Example #13
Source File: SpecialkeyPanel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** 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);
}
 
Example #14
Source File: SkillCalculator.java    From plugins with GNU General Public License v3.0 5 votes vote down vote up
private FocusAdapter buildFocusAdapter(Consumer<FocusEvent> focusLostConsumer)
{
	return new FocusAdapter()
	{
		@Override
		public void focusLost(FocusEvent e)
		{
			focusLostConsumer.accept(e);
		}
	};
}
 
Example #15
Source File: BrowserUnavailableDialogFactory.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #16
Source File: SelectAllOnFocusGainWidget.java    From radiance with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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);
}
 
Example #17
Source File: GenericCellEditor.java    From workcraft with MIT License 5 votes vote down vote up
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();
            }
        }
    });
}
 
Example #18
Source File: JSettingsDialog.java    From cncgcodecontroller with MIT License 5 votes vote down vote up
public SInteger(String label, int value) {
    super(label, String.valueOf(value));
    
    super.jTF.addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) 
        {
            String message=null;
            int v;
            try {
                v = Integer.parseInt(SInteger.this.getText());
                message=getMessage(v);
                if(message==null){   
                    v=Integer.valueOf(SInteger.super.jTF.getText());
                }
                SInteger.super.jTF.setText(String.valueOf(v));
            } catch (NumberFormatException ex) {
                message=ex.toString();
            }
            if(message!=null){
                
                NumberFieldManipulator.popUpToolTip(message, jTF);
                SInteger.super.jTF.requestFocusInWindow();
            }

        }
    });
}
 
Example #19
Source File: ResolveDeclarationsPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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);

}
 
Example #20
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
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);
}
 
Example #21
Source File: UrlComboBox.java    From rest-client with Apache License 2.0 5 votes vote down vote up
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: EnumEditor.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void addChangeListener(final ChangeListener l) {
    final GenericTagEditor t = this;
    addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            l.change(t);
        }
    });
}
 
Example #23
Source File: Amf3ValueEditor.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void addChangeListener(final ChangeListener l) {
    final GenericTagEditor t = this;
    editor.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            l.change(t);
        }

    });
}
 
Example #24
Source File: SwingClientGUI.java    From stendhal with GNU General Public License v2.0 5 votes vote down vote up
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();
		}
	});
}
 
Example #25
Source File: NumberEditor.java    From jpexs-decompiler with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void addChangeListener(final ChangeListener l) {
    final GenericTagEditor t = this;
    addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            l.change(t);
        }

    });
}
 
Example #26
Source File: SkillCalculator.java    From runelite with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private FocusAdapter buildFocusAdapter(Consumer<FocusEvent> focusLostConsumer)
{
	return new FocusAdapter()
	{
		@Override
		public void focusLost(FocusEvent e)
		{
			focusLostConsumer.accept(e);
		}
	};
}
 
Example #27
Source File: AbstractModalDialog.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
protected final JButton buildDialogButton(String buttonText) {
    JButton button = new JButton(buttonText);
    button.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent event) {
            getJDialog().requestFocusInWindow();
        }
    });
    Dimension size = button.getPreferredSize();
    size.width = 75;
    button.setPreferredSize(size);
    return button;
}
 
Example #28
Source File: SwingDialog.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
public JFXPanelEx(){
    addFocusListener(new FocusAdapter() {
        @Override
        public void focusLost(FocusEvent e) {
            hidePopUps();
        }
    });
}
 
Example #29
Source File: ArchetypePropertiesStep.java    From aem-ide-tooling-4-intellij with Apache License 2.0 5 votes vote down vote up
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();
                }
            }
        }
    );
}
 
Example #30
Source File: Content.java    From desktopclient-java with GNU General Public License v3.0 5 votes vote down vote up
Content(View view, ChatView chatView) {
    mView = view;
    mChatView = chatView;

    this.addFocusListener(new FocusAdapter() {
        @Override
        public void focusGained(FocusEvent e) {
            // maybe not visible, i don't care
            mChatView.requestFocusInWindow();
        }
    });

    this.show(mChatView);
}