本文整理了Java中javax.swing.JTextField.setSelectionStart()
方法的一些代码示例,展示了JTextField.setSelectionStart()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextField.setSelectionStart()
方法的具体详情如下:
包路径:javax.swing.JTextField
类名称:JTextField
方法名:setSelectionStart
暂无
代码示例来源:origin: apache/pdfbox
public void reFocus()
{
searchField.requestFocus();
String searchKey = searchField.getText();
searchField.setText(searchKey);
searchField.setSelectionStart(0);
searchField.setSelectionEnd(searchField.getText().length());
closeAction.setEnabled(true);
}
代码示例来源:origin: kaikramer/keystore-explorer
@Override
public void run() {
jtfAlias.requestFocus();
if (alias != null) {
jtfAlias.setSelectionStart(0);
jtfAlias.setSelectionEnd(alias.length());
}
}
});
代码示例来源:origin: net.sf.taverna.t2.ui-components/design-ui
/**
* Sets the port name.
*
* @param name the name of the port
*/
public void setPortName(String name) {
portNameField.setText(name);
// Select the text
if (name.length() > 0){
portNameField.setSelectionStart(0);
portNameField.setSelectionEnd(name.length());
}
}
代码示例来源:origin: stackoverflow.com
@Override
public void actionPerformed(ActionEvent e) {
int row = table.getSelectedRow();
int col = table.getSelectedColumn();
table.editCellAt(row, col);
JTextField field = (JTextField) ((DefaultCellEditor) table
.getCellEditor()).getComponent();
field.requestFocus();
field.setSelectionStart(0);
int endSelection =
(!field.getText().isEmpty()) ? field.getText().length() -1 : 0;
field.setSelectionEnd(endSelection);
}
代码示例来源:origin: mucommander/mucommander
/**
* Sets the given {@link JTextField}'s text, selection start and end with that contained by this
* <code>PathFieldContent</code>.
*
* @param pathField instance of {@link JTextField} to update
*/
public void feedToPathField(JTextField pathField) {
// Set the initial path
pathField.setText(path);
// Text is selected so that user can directly type and replace path
pathField.setSelectionStart(selectionStart);
pathField.setSelectionEnd(selectionEnd);
}
}
代码示例来源:origin: ontopia/ontopia
public void setSearchFocus() {
searchTextField.setSelectionStart(0);
searchTextField.setSelectionEnd(searchTextField.getText().length());
searchTextField.requestFocus();
}
代码示例来源:origin: net.sf.taverna.t2.ui-components/design-ui
/**
* Sets the port name.
*
* @param name the name of the port
*/
public void setPortName(String name) {
portNameField.setText(name);
// Select the text
if (name.length() > 0){
portNameField.setSelectionStart(0);
portNameField.setSelectionEnd(name.length());
}
}
代码示例来源:origin: stackoverflow.com
JTextField textField = new JTextField(10);
textField.setText("Type in something here");
textField.setSelectionStart(0);
textField.setSelectionEnd(textField.getText().length());
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-swingapp
private void setValidValue(boolean valid) {
validValue = valid;
invalidLabel.setVisible(!valid);
valueTextField.setToolTipText(valid ? null : invalidLabel.getToolTipText());
if (!valid) {
valueTextField.setSelectionStart(0);
valueTextField.setSelectionEnd(valueTextField.getDocument().getLength());
}
}
代码示例来源:origin: mucommander/mucommander
/**
* Overrides this method to ignore events received when this component is disabled.
*/
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
if(enabled) {
input.setSelectionStart(0);
input.setSelectionEnd(input.getText().length());
}
}
代码示例来源:origin: stackoverflow.com
final JTextField tf = new JTextField("click here ^");
tf.addMouseListener(new MouseAdapter(){
@Override
public void mousePressed(MouseEvent e){
try{
Rectangle rect = tf.modelToView(0);//for y value
System.out.println(tf.viewToModel(new Point(e.getX(), rect.y)));
int loc = tf.viewToModel(new Point(e.getX(), rect.y));
tf.setSelectionStart(loc);
tf.setSelectionEnd(loc);
}catch(Exception ex){}//swallow the exception for demonstration only
}
});
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-utils-ui
private void addButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
// Add your handling code here:
String value = itemField.getText();
if (value.length() == 0 || itemsVector.contains(value)) {
return;
}
itemsVector.addElement (value);
itemList.setListData (itemsVector);
itemList.setSelectedIndex (-1);
itemField.setSelectionStart(0);
itemField.setSelectionEnd(itemField.getText().length());
itemList.repaint ();
updateValue ();
}//GEN-LAST:event_addButtonActionPerformed
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-j2ee-sun-appsrv
/** Creates new form PasswordPanel */
public PasswordPanel(String userName) {
initComponents();
usernameField.setText(userName);
usernameField.setSelectionStart(0);
usernameField.setSelectionEnd(userName.length());
usernameField.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_UserNameField"));
passwordField.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_PasswordField"));
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-utils
private void addButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
// Add your handling code here:
String value = itemField.getText();
if (value.length() == 0 || itemsVector.contains(value)) {
return;
}
itemsVector.addElement (value);
itemList.setListData (itemsVector);
itemList.setSelectedIndex (-1);
itemField.setSelectionStart(0);
itemField.setSelectionEnd(itemField.getText().length());
itemList.repaint ();
updateValue ();
}//GEN-LAST:event_addButtonActionPerformed
代码示例来源:origin: chatty/chatty
public void addCustomInput() {
add(customReasonInput, customInputGbc);
revalidate();
customReasonInput.requestFocusInWindow();
customReasonInput.setSelectionStart(0);
customReasonInput.setSelectionEnd(customReasonInput.getText().length());
}
代码示例来源:origin: mucommander/mucommander
/**
* Creates the panel in which we'll store the label and name field.
* @param name current name.
* @return the panel in which we'll store the label and name field.
*/
private JPanel createNamePanel(String name) {
XAlignedComponentPanel panel;
panel = new XAlignedComponentPanel(5);
nameField = new JTextField();
nameField.setText(name);
nameField.setSelectionStart(0);
nameField.setSelectionEnd(name.length());
panel.addRow(Translator.get("name"), nameField, 0);
return panel;
}
代码示例来源:origin: mucommander/mucommander
public BatchRenameSelectRange(Dialog owner, String filename) {
super(owner, Translator.get("batch_rename_dialog.range"), owner);
edtRange = new JTextField();
ReadOnlyDocument doc = new ReadOnlyDocument();
edtRange.setDocument(doc);
edtRange.setText(filename);
edtRange.setColumns(filename.length() + 5);
edtRange.setSelectionStart(0);
edtRange.setSelectionEnd(filename.length());
doc.setReadOnly(true);
Container content = getContentPane();
content.setLayout(new BorderLayout());
content.add(edtRange, BorderLayout.CENTER);
btnOK = new JButton(Translator.get("ok"));
btnCancel = new JButton(Translator.get("cancel"));
content.add(DialogToolkit.createOKCancelPanel(btnOK, btnCancel, getRootPane(), this), BorderLayout.SOUTH);
}
代码示例来源:origin: EngineHub/CommandHelper
@Override
public void actionPerformed(ActionEvent e) {
setEnabledAll(true);
Bookmark b = new Bookmark();
b.name = "New Bookmark";
populateFromBookmark(b);
blist.addBookmark(b);
bookmarkList.setListData(blist.getNameList());
bookmarkList.setSelectedValue(b.name, true);
nameField.requestFocus();
nameField.setSelectionStart(0);
nameField.setSelectionEnd(b.name.length());
}
});
代码示例来源:origin: RPTools/maptool
public EditLabelPanel(EditLabelDialog dialog) {
super("net/rptools/maptool/client/ui/forms/editLabelDialog.xml");
this.dialog = dialog;
panelInit();
getLabelTextField().setSelectionStart(0);
getLabelTextField().setSelectionEnd(getLabelTextField().getText().length());
getLabelTextField().setCaretPosition(getLabelTextField().getText().length());
}
代码示例来源:origin: org.protege/protege-editor-owl
private void handleURISyntaxException(URISyntaxException e) {
int actualIndex = e.getIndex();
String fullURI = e.getInput();
int indexFromRHS = fullURI.length()-actualIndex;
int relativeIndex = getEntityName().length() - indexFromRHS;
textField.setSelectionStart(relativeIndex);
textField.setSelectionEnd(getEntityName().length());
displayWarningMessage("Invalid name: " + e.getReason());
}
内容来源于网络,如有侵权,请联系作者删除!