本文整理匯總了Java中javax.swing.JTextField.requestFocus方法的典型用法代碼示例。如果您正苦於以下問題:Java JTextField.requestFocus方法的具體用法?Java JTextField.requestFocus怎麽用?Java JTextField.requestFocus使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.JTextField
的用法示例。
在下文中一共展示了JTextField.requestFocus方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: FreeColStringInputDialog
import javax.swing.JTextField; //導入方法依賴的package包/類
/**
* Creates a dialog to input a string field.
*
* @param freeColClient The {@code FreeColClient} for the game.
* @param frame The owner frame.
* @param modal True if this dialog should be modal.
* @param text Text that explains the action to the user.
* @param defaultValue The default value appearing in the text field.
* @param okKey A key displayed on the "ok"-button.
* @param cancelKey A key displayed on the optional "cancel"-button.
*/
public FreeColStringInputDialog(FreeColClient freeColClient, JFrame frame,
boolean modal, String text, String defaultValue,
String okKey, String cancelKey) {
super(freeColClient, frame);
textField = new JTextField(defaultValue);
textField.setOpaque(false);
JPanel panel = new JPanel(new BorderLayout()) {
@Override
public void requestFocus() {
textField.requestFocus();
}
};
panel.setOpaque(false);
panel.add(Utility.getDefaultTextArea(text));
panel.add(textField, BorderLayout.PAGE_END);
initializeInputDialog(frame, modal, panel, null, okKey, cancelKey);
}
示例2: doComboBoxAction
import javax.swing.JTextField; //導入方法依賴的package包/類
@Override
protected void doComboBoxAction() {
if (comboBox.getSelectedIndex() > 0) {
// get the params of the selected resource type.
paramNames = new ArrayList<String>();
paramValues = new ArrayList<JTextField>();
for (final Method m : ((ComboBoxClass) comboBox.getSelectedItem())
.getClasss().getDeclaredMethods()) {
// for every setter method get the name of the parameter to set
// and display it as a label along with a text field for setting
// the value.
if (m.isAnnotationPresent(ExchangeParameter.class)
&& m.getName().startsWith("set")) {
String name = m.getName().substring(3).toLowerCase();
paramNames.add(name);
JLabel paramName = new JLabel(name.replaceFirst("demanded",
"demanded "));
paramName.setVisible(true);
paramsPanel.add(paramName);
JTextField paramValue = new JTextField(3);
paramValue.setEditable(true);
paramValue.setVisible(true);
paramValues.add(paramValue);
paramsPanel.add(paramValue);
paramValue.requestFocus();
}
}
}
}
示例3: doComboBoxAction
import javax.swing.JTextField; //導入方法依賴的package包/類
@Override
protected void doComboBoxAction() {
if (comboBox.getSelectedIndex() > 0) {
// get params of the selected resource type
paramNames = new ArrayList<String>();
paramValues = new ArrayList<JTextField>();
AbstractConstraint selectedCons = ((ComboBoxConstraint) comboBox
.getSelectedItem()).getConstraint();
for (final Method m : selectedCons.getClass().getDeclaredMethods()) {
if (m.isAnnotationPresent(ExchangeParameter.class)
&& m.getName().startsWith("set")) {
// For every setter method get the name of the parameter to
// set and display it as a label along with a text field for
// setting the value.
String name = m.getName().substring(3).toLowerCase();
paramNames.add(name);
JLabel paramName = new JLabel(name.replaceFirst("demanded",
"demanded "));
paramName.setVisible(true);
paramsPanel.add(paramName);
JTextField paramValue = new JTextField(3);
try {
paramValue
.setText(selectedCons
.getClass()
.getMethod(
"get"
+ m.getName()
.substring(3),
new Class<?>[0])
.invoke(selectedCons, new Object[0])
.toString());
} catch (Exception e) {
e.printStackTrace();
throw new AssertionError(
"Error occurred while trying to access a get Metdod of the Object "
+ entity);
}
paramValue.setEditable(true);
paramValue.setVisible(true);
paramValues.add(paramValue);
paramsPanel.add(paramValue);
paramValue.requestFocus();
}
}
}
}
示例4: setTextField
import javax.swing.JTextField; //導入方法依賴的package包/類
/**For numpad input, sets the text field to a certain text*/
public static void setTextField(JTextField textField, String text)
{
textField.setText(text);
textField.requestFocus();
}
示例5: addToTextField
import javax.swing.JTextField; //導入方法依賴的package包/類
/**For numpad input, adds text to the text field*/
public static void addToTextField(JTextField textField, String add)
{
textField.setText(textField.getText() + add);
textField.requestFocus();
}