Java 类java.awt.event.FocusAdapter 实例源码
项目:incubator-netbeans
文件:EditorUI.java
/** 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();
}
项目:incubator-netbeans
文件:SpecialkeyPanel.java
/** 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);
}
项目:incubator-netbeans
文件:GenerateCodePanel.java
/** 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();
}
});
}
项目:rapidminer
文件:AutoCompletionComboBox.java
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"));
}
});
}
项目:openjdk-jdk10
文件:SystemSelectionAWTTest.java
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");
}
项目:openjdk-jdk10
文件:SystemSelectionSwingTest.java
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");
}
项目:openjdk9
文件:SystemSelectionAWTTest.java
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");
}
项目:openjdk9
文件:SystemSelectionSwingTest.java
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");
}
项目:PhET
文件:TextBoxListener.java
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();
}
} );
}
项目:PhET
文件:TextBoxListener.java
public void addListeners( final TextBox textBox ) {
final MovingMan.Listener listener = new MovingMan.Listener() {
public void changed() {
textBox.setText( decimalFormat.format( model.getMovingMan().getVelocity() ) );
}
};
model.getMovingMan().addListener( listener );
listener.changed();
textBox.addListener( new TextBox.Listener() {
public void changed() {
String text = textBox.getText();//have to store it since the next line modifies it
model.getMovingMan().setVelocityDriven();
model.getMovingMan().setVelocity( Double.parseDouble( text ) );
}
} );
textBox.addFocusListener( new FocusAdapter() {
public void focusGained( FocusEvent e ) {
model.getMovingMan().setVelocityDriven();
}
} );
}
项目:PhET
文件:TextBoxListener.java
public void addListeners( final TextBox textBox ) {
final MovingMan.Listener listener = new MovingMan.Listener() {
public void changed() {
textBox.setText( decimalFormat.format( model.getMovingMan().getAcceleration() ) );
}
};
model.getMovingMan().addListener( listener );
listener.changed();
textBox.addListener( new TextBox.Listener() {
public void changed() {
String text = textBox.getText();//have to store it since the next line modifies it
model.getMovingMan().setAccelerationDriven();
model.getMovingMan().setAcceleration( Double.parseDouble( text ) );
}
} );
textBox.addFocusListener( new FocusAdapter() {
public void focusGained( FocusEvent e ) {
model.getMovingMan().setAccelerationDriven();
}
} );
}
项目:PhET
文件:TargetTextArea.java
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() );
}
});
}
项目:iSeleda
文件:LayerNameEditor.java
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);
});
}
项目:deltahex-intellij-plugin
文件:GoToHexPanel.java
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();
}
});
}
}
});
}
项目:intellij-ce-playground
文件:CopyableLabel.java
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));
}
项目:intellij-ce-playground
文件:EditorWindow.java
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);
}
}
});
}
});
}
项目:intellij-ce-playground
文件:ChangeSignatureDialogBase.java
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;
}
项目:rapidminer-studio
文件:AutoCompletionComboBox.java
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"));
}
});
}
项目:NBModeler
文件:ComboButton.java
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());
}
项目:swingx
文件:JXCollapsiblePaneVisualCheck.java
/**
* Test case for bug 1087. Hidden components should not have focus.
*/
public void interactiveFocusTest() {
JPanel panel = new JPanel(new BorderLayout());
final JXCollapsiblePane instance = new JXCollapsiblePane();
panel.add(instance, BorderLayout.SOUTH);
JButton paneButton = new JButton("I do nothing");
paneButton.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
if (instance.isCollapsed()) {
fail("Why am i getting focus?!");
}
}
});
instance.add(paneButton);
JButton button = new JButton("Toggle");
button.addActionListener(instance.getActionMap().get(
JXCollapsiblePane.TOGGLE_ACTION));
panel.add(button, BorderLayout.CENTER);
showInFrame(panel, "Focus Test");
}
项目:genomeartist
文件:JTextFieldPropertiesEditor.java
/**
* Functie proprie de initializare
*/
private void initialize() {
//Fac layout-ul
this.setLayout(new BorderLayout());
this.add(textfield, BorderLayout.CENTER);
this.add(endingLabel, BorderLayout.EAST);
//Pun o margnie la label
endingLabel.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0));
//Adaug un ascultator de focus
textfield.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
textfield.selectAll();
}
});
//Inregistrez ascultatorii
editorChangeListeners = new Vector<IEditorChangeListener>();
textfield.getDocument().addDocumentListener(this);
}
项目:genomeartist
文件:JTextAreaPropertiesEditor.java
/**
* Functie proprie de initializare
*/
@SuppressWarnings("UseOfObsoleteCollectionType")
private void initialize() {
this.setViewportView(textarea);
//No focus listener because te tab key will erase the values
textarea.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
textarea.selectAll();
}
});
//Inregistrez ascultatorii
editorChangeListeners = new Vector<IEditorChangeListener>();
textarea.getDocument().addDocumentListener(this);
//Setez focusul
registerLocalKeyBindings();
}
项目:genomeartist
文件:JPasswordFieldPropertiesEditor.java
/**
* Functie proprie de initializare
*/
private void initialize() {
//Fac layout-ul
this.setLayout(new BorderLayout());
this.add(passwordField, BorderLayout.CENTER);
this.add(endingLabel, BorderLayout.EAST);
//Pun o margnie la label
endingLabel.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0));
//Adaug un ascultator de focus
passwordField.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
passwordField.selectAll();
}
});
//Inregistrez ascultatorii
editorChangeListeners = new Vector<IEditorChangeListener>();
passwordField.getDocument().addDocumentListener(this);
}
项目:genomeartist
文件:JValidatorTextfield.java
/**
* Contruiesc componenta cu validator
*/
public JValidatorTextfield(IValidateString validator, Border originalBorder) {
super();
this.getDocument().addDocumentListener(this);
//Metoda de a selecta tot textul la click
this.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
super.focusGained(e);
JValidatorTextfield.this.selectAll();
}
});
this.isValid = true;
this.validator = validator;
//Pastrez borderul orginal
if (originalBorder != null)
setBorder(originalBorder);
this.originalBorder = getBorder();
this.problemBorder = new ColorizingBorder(originalBorder,ERROR_COLOR);
}
项目:viewer
文件:HGViewer.java
protected void init(Collection<FNode> nodes, Collection<FEdge> edges)
{
view = new GraphView(this, graph, nodes, edges);
HGVKit.getViewersList().add(view);
view.getCanvas().addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e)
{
focused(HGViewer.this);
}
});
view.addSelectionListener(new GraphView.SelectionListener() {
public void selectionChanged()
{
updateStatusLabel();
}
});
PScrollPane scroll = new PScrollPane(view.canvas);
add(scroll, BorderLayout.CENTER);
addStatusBar();
setPreferredSize(new Dimension(600, 400));
initKeyBindings();
}
项目:metasfresh
文件:ReadPaymentDocumentDialog.java
public static ReadPaymentDocumentDialog create(final Properties ctx,
final Frame parentFrame,
final int AD_Org_ID)
{
//
// Services
final IMsgBL msgBL = Services.get(IMsgBL.class);
final String title = msgBL.getMsg(ctx, ReadPaymentDocumentPanel.HEADER_READ_PAYMENT_STRING);
final ReadPaymentDocumentDialog readPaymentDocumentDialog = new ReadPaymentDocumentDialog(parentFrame, title, AD_Org_ID);
//
// Forward dialog's focus to it's main panel
readPaymentDocumentDialog.addFocusListener(new FocusAdapter()
{
@Override
public void focusGained(final FocusEvent e)
{
final ReadPaymentDocumentPanel dialogComponent = readPaymentDocumentDialog.getDialogComponent();
dialogComponent.focusGained(e);
}
});
return readPaymentDocumentDialog;
}
项目:OAT
文件:AbstractChartFrame.java
private void initComponent() {
setJMenuBar(new MainMenuBar(this));
chartPanel.setPreferredSize(getChartPanelSize());
setContentPane(chartPanel);
setDefaultCloseOperation(disposeOnClose()
? WindowConstants.DISPOSE_ON_CLOSE
: WindowConstants.HIDE_ON_CLOSE);
if (hideWhenFocusLost()) {
addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
setVisible(false);
}
});
}
init();
//pack and display
pack();
}
项目:otroslogviewer
文件:SuggestDecorator.java
/**
* 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);
}
}
});
}
}
项目:PanBox
文件:PanboxClient.java
private void extendPairingInformation(PairingInformation info) {
logger.debug("PanboxClient : extendPairingInformation : Will now extend given device pairing information...");
final JTextField deviceNameField = new JTextField(bundle.getString("PanboxClient.chooseDeviceName"));
deviceNameField.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
if (deviceNameField.getText().equals(bundle.getString("PanboxClient.chooseDeviceName"))) {
deviceNameField.setText("");
}
}
});
JOptionPane.showMessageDialog(null, deviceNameField, bundle.getString("PanboxClient.enterDeviceName"),
JOptionPane.INFORMATION_MESSAGE);
info.setDeviceName(deviceNameField.getText());
logger.debug("PanboxClient : extendPairingInformation : Set device name to: " + info.getDeviceName());
}
项目:yummy-xml-UI
文件:DefaultWebLoadAction.java
@Override
protected void installWebBroswerAction() {
final SwingBrowser sb = (SwingBrowser) owner;
sb.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
sb.loadURL(url);
}
});
}
});
}
项目:aibench-project
文件:PrimitiveParamProvider.java
public PrimitiveParamProvider(ParamsReceiver receiver, Port p, Class<?> clazz, Object operationObject) {
super(receiver, p,clazz,operationObject);
this.field.setPreferredSize(new Dimension(150, this.field.getPreferredSize().height));
this.field.setText(p.defaultValue().toString());
this.field.addKeyListener(this);
this.booleanCheck.addActionListener(this);
this.field.addFocusListener(new FocusAdapter() {
public void focusGained(FocusEvent e) {
if (e.getComponent() instanceof JTextField) {
((JTextField) e.getComponent()).selectAll();
}
};
});
}
项目:jspresso-ce
文件:JEditTextAreaConnector.java
/**
* {@inheritDoc}
*/
@Override
protected void bindJComponent() {
getConnectedJComponent().addFocusListener(new FocusAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void focusLost(FocusEvent e) {
if (!e.isTemporary()) {
fireConnectorValueChange();
}
}
});
}
项目:jspresso-ce
文件:JTextComponentConnector.java
/**
* {@inheritDoc}
*/
@Override
protected void bindJComponent() {
getConnectedJComponent().addFocusListener(new FocusAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void focusLost(FocusEvent e) {
if (!e.isTemporary()) {
fireConnectorValueChange();
}
}
});
}
项目:jspresso-ce
文件:JActionFieldConnector.java
/**
* {@inheritDoc}
*/
@Override
protected void bindJComponent() {
getConnectedJComponent().addTextFieldFocusListener(new FocusAdapter() {
/**
* {@inheritDoc}
*/
@Override
public void focusLost(FocusEvent e) {
if (!e.isTemporary()) {
performActionIfNeeded();
}
}
});
}
项目:jspresso-ce
文件:JDateField.java
private void initDefaultBehaviour(Locale locale) {
setRenderer(new FixedDayRenderer());
setHeaderRenderer(new TranslatedHeaderRenderer(locale));
new FormatSymbols((DateFormatter) getFormattedTextField().getFormatter(),
locale);
getFormattedTextField().setBorder(
BorderFactory.createEmptyBorder(1, 5, 1, 5));
SwingUtil.enableSelectionOnFocusGained(getFormattedTextField());
addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
if (!e.isTemporary()) {
JTextField tf = ((DateField) e.getSource()).getFormattedTextField();
tf.requestFocusInWindow();
}
}
});
setValue(null);
}
项目:platypus-js
文件:VTextArea.java
public VTextArea(String aText) {
super();
super.setText(aText != null ? aText : "");
if (aText == null) {
nullValue = true;
}
oldValue = aText;
super.addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
String text = getText();
if (text != null && !"".equals(text)) {
nullValue = false;
}
checkValueChanged();
}
});
}
项目:passage
文件:EditableOMRangeRings.java
private JTextField makeIntervalField() {
JTextField field = new JTextField(Integer.toString(((OMRangeRings) circle).getInterval()), 5);
field.setMargin(new Insets(0, 1, 0, 1));
// without minimum size set, field can be too small to use
field.setMinimumSize(new Dimension(40, 18));
field.setHorizontalAlignment(JTextField.RIGHT);
field.setToolTipText(i18n.get(this, "intervalField.tooltip", "Value for interval between rings."));
field.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
updateInterval(((JTextField) (ae.getSource())).getText());
}
});
// Users forget to hit Enter, which is required for an action event,
// then wonder why the rings they draw don't have the desired value.
// Adding a focus listener addresses this issue.
field.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent event) {
if (!event.isTemporary()) {
updateInterval(((JTextField) (event.getSource())).getText());
}
}
});
return field;
}
项目:svarog
文件:MontageMiscellaneousPanel.java
public TextPanePanel getEditDescriptionPanel() {
if (editDescriptionPanel == null) {
editDescriptionPanel = new TextPanePanel(_("Edit description"));
editDescriptionPanel.setPreferredSize(new Dimension(300,200));
editDescriptionPanel.setMinimumSize(new Dimension(300,200));
editDescriptionPanel.getTextPane().addFocusListener(new FocusAdapter() {
@Override
public void focusLost(FocusEvent e) {
if (montage != null) {
String description = editDescriptionPanel.getTextPane().getText();
// XXX: this doesn't look good
if (description == null || description.isEmpty()) {
montage.setDescription(description);
}
}
}
});
}
return editDescriptionPanel;
}
项目:OtrosSuggestBox
文件:SuggestDecorator.java
/**
* 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);
}
}
});
}
}
项目:snap-desktop
文件:FilePanel.java
public FilePanel() {
super(new BorderLayout());
this.textField = new JTextField();
this.textField.setBorder(new EmptyBorder(0, 0, 0, 0));
this.browseButton = new JButton("...");
browseButton.setFocusable(false);
Dimension size = new Dimension(26, 16);
browseButton.setPreferredSize(size);
browseButton.setMinimumSize(size);
addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent event) {
textField.requestFocusInWindow();
}
});
add(this.textField, BorderLayout.CENTER);
add(browseButton, BorderLayout.EAST);
}