本文整理汇总了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();
}