本文整理了Java中javax.swing.JTextField.getCaretPosition()
方法的一些代码示例,展示了JTextField.getCaretPosition()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextField.getCaretPosition()
方法的具体详情如下:
包路径:javax.swing.JTextField
类名称:JTextField
方法名:getCaretPosition
暂无
代码示例来源:origin: cmu-phil/tetrad
/**
* States whether the caret is in the getModel selection, if not false is returned and
* all the selections are removed (as the user moved the caret around).
*/
private boolean caretInSelection(Selection sel) {
int caret = this.expression.getCaretPosition();
if (caret < sel.x || sel.y < caret) {
this.selections.clear();
return false;
}
return true;
}
代码示例来源:origin: org.gephi/directory-chooser
private boolean isCompletionKey (int keyCode, JTextField textField) {
if (keyCode == KeyEvent.VK_ENTER || keyCode == KeyEvent.VK_TAB) {
return true;
}
if (keyCode == KeyEvent.VK_RIGHT &&
(textField.getCaretPosition() >= (textField.getDocument().getLength() - 1))) {
return true;
}
return false;
}
代码示例来源:origin: omegat-org/omegat
private void insertButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_insertButtonActionPerformed
int caret = targetFilenamePatternField.getCaretPosition();
String oldtext = targetFilenamePatternField.getText();
String newtext = oldtext.substring(0, caret) + substitute.getSelectedItem().toString()
+ oldtext.substring(caret);
targetFilenamePatternField.setText(newtext);
targetFilenamePatternField.setCaretPosition(caret + substitute.getSelectedItem().toString().length());
targetFilenamePatternField.requestFocus();
}//GEN-LAST:event_insertButtonActionPerformed
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-junit-ui
public void ensureCursorInRange() {
if (srcGroupNameDisplayed) {
if (tfClassToTest.getCaretPosition() > classNameLength) {
tfClassToTest.setCaretPosition(classNameLength);
}
}
}
}
代码示例来源:origin: lbalazscs/Pixelitor
public void actionPerformed(ActionEvent e) {
if(uncommittedText!=null) {
int pos = hexField.getCaretPosition();
pos = Math.min(pos, uncommittedText.length());
hexField.setText(uncommittedText);
hexField.setCaretPosition(pos);
}
}
});
代码示例来源:origin: dubbo/jmeter-plugins-dubbo
public void keyReleased(KeyEvent e) {
char ch = e.getKeyChar();
if (ch == KeyEvent.VK_ENTER) {
int caretPosition = editor.getCaretPosition();
String str = editor.getText();
if (str.length() == 0)
return;
autoComplete(str, caretPosition);
}
// if (ch == KeyEvent.CHAR_UNDEFINED || Character.isISOControl(ch)
// || ch == KeyEvent.VK_DELETE)
// return;
}
代码示例来源:origin: stackoverflow.com
PropertyChangeListener pl = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (!(evt.getNewValue() instanceof JTextField)) return;
JTextField field = (JTextField) evt.getNewValue();
// crude check to not overdo it
int dot = field.getCaretPosition();
if (dot == 0) {
field.selectAll();
}
}
};
KeyboardFocusManager.getCurrentKeyboardFocusManager()
.addPropertyChangeListener("permanentFocusOwner", pl);
代码示例来源:origin: pvto/konte-art
private void change()
{
JTextField f = jTextField1;
int car = jTextField1.getCaretPosition();
f.setText(f.getText().replaceAll("[^\\w]", "").toUpperCase());
car = Math.min(car, f.getText().length());
setRndCharSlider(f.getText());
try {
jTextField1.setCaretPosition(car);
} catch(Exception eee) { }
}
代码示例来源:origin: omegat-org/omegat
/**
* Insert the specified text into the currently active (focused) search field: either Search or Replace
*
* @param text
* The text to insert
*/
public void insertIntoActiveField(String text) {
JTextField editor = getActiveFieldEditor();
int offset = editor.getCaretPosition();
try {
editor.getDocument().insertString(offset, text, null);
} catch (BadLocationException ignore) {
}
}
代码示例来源:origin: lbalazscs/Pixelitor
public void run() {
int pos = hexField.getCaretPosition();
setRGB(red, green, blue);
pos = Math.min(pos, hexField.getText().length());
hexField.setCaretPosition(pos);
}
}
代码示例来源:origin: org.nuiton.jaxx/jaxx-widgets
@Override
public void processDataBinding() {
if (getModelText() != null && textField != null) {
$JButton7.setEnabled(!(getModelText().isEmpty() || textField.getCaretPosition() ==0 ));
}
}
代码示例来源:origin: igniterealtime/Spark
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_RIGHT &&
((JTextField)e.getSource()).getCaretPosition()==((JTextField)e.getSource()).getText().length())
{
getPopup().show(otherUsers,0,0);
}
}
代码示例来源:origin: sdedit/sdedit
protected void _actionPerformed(ActionEvent e) {
int c = textField.getCaretPosition();
applyValue(textField.getText());
textField.setCaretPosition(c);
}
代码示例来源:origin: gurkenlabs/litiengine
private void autoComplete() {
String autoCompletion = this.findAutoCompletion(this.textFieldInput.getText());
if (autoCompletion == null) {
return;
}
final int currentCaretPosition = this.textFieldInput.getCaretPosition();
this.textFieldInput.setText(autoCompletion);
this.validate();
this.textFieldInput.setCaretPosition(this.textFieldInput.getText().length());
this.textFieldInput.moveCaretPosition(currentCaretPosition);
}
代码示例来源:origin: io.ultreia.java4all.jaxx/jaxx-widgets-number
/**
* Ajoute le caractère donné à l'endroit où est le curseur dans la zone de
* saisie et met à jour le modèle.
*
* @param c le caractère à ajouter.
*/
public void addChar(char c) {
try {
ui.getTextField().getDocument().insertString(ui.getTextField().getCaretPosition(), c + "", null);
} catch (BadLocationException e) {
log.warn(e);
}
setTextValue(ui.getTextField().getText());
}
代码示例来源:origin: org.nuiton.jaxx/jaxx-widgets
/**
* Ajoute le caractère donné à l'endroit où est le curseur dans la zone de
* saisie et met à jour le modèle.
*
* @param s le caractère à ajouter.
*/
public void addChar(String s) {
char c = s.charAt(0);
try {
editor.getTextField().getDocument().insertString(editor.getTextField().getCaretPosition(), c + "", null);
setModel(editor.getTextField().getText());
//setModel(editor.getModelText() + c);
} catch (BadLocationException e) {
log.warn(e);
}
}
代码示例来源:origin: org.nuiton.jaxx/jaxx-runtime-swing-widget
/**
* Ajoute le caractère donné à l'endroit où est le curseur dans la zone de
* saisie et met à jour le modèle.
*
* @param s le caractère à ajouter.
*/
public void addChar(String s) {
char c = s.charAt(0);
try {
editor.getTextField().getDocument().insertString(editor.getTextField().getCaretPosition(), c + "", null);
setModel(editor.getTextField().getText());
//setModel(editor.getModelText() + c);
} catch (BadLocationException e) {
log.warn(e);
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-ruby-platform
private void applyFilter(final TabIndex tab,
final JTextField searchField, final JList list,
final JTextPane desc, final JButton button) {
// keep search filter fields in sync
int pos = searchField.getCaretPosition();
String _filter = getFilter();
searchField.setText(_filter);
searchField.setCaretPosition(pos > _filter.length() ? _filter.length() : pos);
GemListModel gemModel = (GemListModel) list.getModel();
gemModel.applyFilter(getFilter());
setTabTitle(tab, gemModel);
if (list.getSelectedValue() == null) {
list.setSelectedIndex(0);
}
updateGemDescription(list, desc, button);
}
代码示例来源:origin: cmu-phil/tetrad
public void focusLost(FocusEvent e) {
JTextField textField = (JTextField) e.getSource();
this.start = textField.getSelectionStart();
this.end = textField.getSelectionEnd();
this.caretPosition = textField.getCaretPosition();
}
}
代码示例来源:origin: PavlikPolivka/GitLabProjects
@Override
public void keyReleased(KeyEvent e) {
String str = comboBoxEditor.getItem().toString();
JTextField jtf = (JTextField) comboBoxEditor.getEditorComponent();
int currentPosition = jtf.getCaretPosition();
if (e.getKeyChar() == KeyEvent.CHAR_UNDEFINED) {
if (e.getKeyCode() != KeyEvent.VK_ENTER) {
comboBoxEditor.setItem(str);
jtf.setCaretPosition(currentPosition);
}
} else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
comboBox.setSelectedIndex(comboBox.getSelectedIndex());
} else {
updateModel(comboBox.getEditor().getItem().toString());
comboBoxEditor.setItem(str);
jtf.setCaretPosition(currentPosition);
}
}
内容来源于网络,如有侵权,请联系作者删除!