本文整理汇总了Java中javax.swing.JTextField.addActionListener方法的典型用法代码示例。如果您正苦于以下问题:Java JTextField.addActionListener方法的具体用法?Java JTextField.addActionListener怎么用?Java JTextField.addActionListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JTextField
的用法示例。
在下文中一共展示了JTextField.addActionListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTableCellEditorComponent
import javax.swing.JTextField; //导入方法依赖的package包/类
@Override
public Component getTableCellEditorComponent(JTable table, Object value,
boolean isSelected,
int row, int column) {
JComponent c = (JComponent)super.getTableCellEditorComponent(table, value, isSelected, row, column);
cell.setText((String) value);
this.orig = cell.getTextField().getText();
this.action = ((ActionHolder) table.getValueAt(row, 0)).getAction();
final JTextField textField = cell.getTextField();
textField.addActionListener(delegate);
textField.setBorder(new LineBorder(Color.BLACK));
if(!Arrays.asList(textField.getKeyListeners()).contains(escapeAdapter)) {
textField.addKeyListener(escapeAdapter);
}
// allow the UI delegate to replace the background with more sensible color
cell.setBgColor(c.getBackground());
cell.setFgCOlor(c.getForeground(), false);
SwingUtilities.invokeLater(new Runnable() {
public void run() {
textField.requestFocus();
}
});
return cell;
}
示例2: dataPanel
import javax.swing.JTextField; //导入方法依赖的package包/类
protected Component dataPanel() {
JPanel panel = new JPanel(new GridLayout(1, 2, 0, 8));
panel.setBorder(BorderFactory.createEmptyBorder(20, 5, 20, 30));
JLabel label = new JLabel("Record tittle:");
label.setFont(new Font("Arial", Font.BOLD, 20));
label.setHorizontalAlignment(JTextField.CENTER);
textField = new JTextField();
textField.setFont(new Font("Arial", Font.BOLD, 20));
textField.setHorizontalAlignment(JTextField.RIGHT);
textField.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
accept.requestFocusInWindow();
}
});
panel.add(label);
panel.add(textField);
return panel;
}
示例3: ChatPanel
import javax.swing.JTextField; //导入方法依赖的package包/类
/**
* The constructor that will add the items to this panel.
*
* @param freeColClient The {@code FreeColClient} for the game.
*/
public ChatPanel(FreeColClient freeColClient) {
super(freeColClient, new BorderLayout(10, 10));
JLabel label = Utility.localizedLabel("chatPanel.message");
field = new JTextField("", 40);
field.setActionCommand(String.valueOf(CHAT));
field.addActionListener(this);
add(label);
add(field);
//setFocusable(false);
label.setFocusable(false);
field.setFocusable(true);
setSize(getPreferredSize());
}
示例4: createTopPane
import javax.swing.JTextField; //导入方法依赖的package包/类
private JComponent createTopPane() {
inputField = new JTextField(40);
inputField.addActionListener( (e) -> sendMessage() );
inputField.setMaximumSize( inputField.getPreferredSize() );
JButton sendButton = new JButton( getLocalizedComponentText("sendButton") );
sendButton.addActionListener( (e) -> sendMessage() );
JPanel pane = new JPanel();
pane.setLayout( new BoxLayout(pane, BoxLayout.LINE_AXIS) );
crSwitch = new JToggleButton("CR", true);
lfSwitch = new JToggleButton("LF", true);
pane.add( inputField );
pane.add( Box.createRigidArea( new Dimension(5, 0) ) );
pane.add( sendButton );
pane.add( Box.createGlue() );
pane.add( crSwitch );
pane.add( Box.createRigidArea( new Dimension(5, 0) ) );
pane.add( lfSwitch );
pane.setBorder( BorderFactory.createEmptyBorder(3, 3, 3, 0) );
return pane;
}
示例5: ResultSetTableCellEditor
import javax.swing.JTextField; //导入方法依赖的package包/类
public ResultSetTableCellEditor(final JTextField textField) {
super(textField);
delegate = new EditorDelegate() {
@Override
public void setValue(Object value) {
val = value;
textField.setText((value != null) ? value.toString() : "");
}
@Override
public boolean isCellEditable(EventObject evt) {
if (evt instanceof MouseEvent) {
return ((MouseEvent) evt).getClickCount() >= 2;
}
return true;
}
@Override
public Object getCellEditorValue() {
String txtVal = textField.getText();
if (val == null && txtVal.equals("")) {
return null;
} else {
return txtVal;
}
}
};
textField.addActionListener(delegate);
// #204176 - workarround for MacOS L&F
textField.setCaret(new DefaultCaret());
}
示例6: buildEditor
import javax.swing.JTextField; //导入方法依赖的package包/类
private JPanel buildEditor()
{
JPanel editor = new JPanel(new GridBagLayout());
editor.setBorder(new EmptyBorder(10, 30, 10, 30));
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 0.5;
gbc.gridx = 0;
gbc.gridy = 0;
editor.add(new JLabel("Textur Atlas"), gbc);
gbc.gridx++;
atlasTextField = new JTextField(level.getAtlas());
atlasTextField.addActionListener(this);
editor.add(atlasTextField, gbc);
gbc.gridy++;
gbc.gridx = 0;
gbc.gridwidth = 2;
gbc.insets.top = 20;
saveButton = new JButton("Übernehmen");
saveButton.addActionListener(this);
editor.add(saveButton, gbc);
return editor;
}
示例7: buildEditor
import javax.swing.JTextField; //导入方法依赖的package包/类
private JPanel buildEditor(String text)
{
JPanel editor = new JPanel(new GridBagLayout());
editor.setBorder(new EmptyBorder(10, 30, 10, 30));
GridBagConstraints gbc = new GridBagConstraints();
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.weightx = 0.5;
gbc.gridx = 0;
gbc.gridy = 0;
editor.add(new JLabel("Text"), gbc);
gbc.gridy++;
contentTextField = new JTextField(text);
contentTextField.addActionListener(this);
editor.add(contentTextField, gbc);
gbc.gridy++;
gbc.gridx = 0;
gbc.insets.top = 20;
saveButton = new JButton("Übernehmen");
saveButton.addActionListener(this);
editor.add(saveButton, gbc);
gbc.insets.top = 0;
gbc.gridy++;
removeButton = new MetalGradientButton("Text entfernen");
removeButton.addActionListener(this);
removeButton.setBackground(Color.RED.darker());
removeButton.setEnabled(canRemove);
editor.add(removeButton, gbc);
return editor;
}
示例8: QueryColorChooser
import javax.swing.JTextField; //导入方法依赖的package包/类
public QueryColorChooser(
String name,
String defaultColor) {
super(BoxLayout.X_AXIS);
_defaultColor = defaultColor;
_entryBox = new JTextField(defaultColor, _width);
JButton button = new JButton("Choose");
button.addActionListener(this);
add(_entryBox);
add(button);
// Add the listener last so that there is no notification
// of the first value.
_entryBox.addActionListener(new QueryActionListener(name));
// Add a listener for loss of focus. When the entry gains
// and then loses focus, listeners are notified of an update,
// but only if the value has changed since the last notification.
// FIXME: Unfortunately, Java calls this listener some random
// time after the window has been closed. It is not even a
// a queued event when the window is closed. Thus, we have
// a subtle bug where if you enter a value in a line, do not
// hit return, and then click on the X to close the window,
// the value is restored to the original, and then sometime
// later, the focus is lost and the entered value becomes
// the value of the parameter. I don't know of any workaround.
_entryBox.addFocusListener(new QueryFocusListener(name));
_name = name;
}
示例9: openDataWindow
import javax.swing.JTextField; //导入方法依赖的package包/类
public void openDataWindow() {
contentPane = new JPanel( new BorderLayout( 10, 10 ) );
Border emptyBorder = BorderFactory.createEmptyBorder(10, 10, 10, 10);
contentPane.setBorder( emptyBorder );
searchPane = new JPanel( new BorderLayout( 5, 5 ) );
top = new DefaultMutableTreeNode();
okButton = new JButton("OK");
okButton.addActionListener(this);
searchBar = new JTextField(20);
searchBar.setText(defaultSearchBarText);
searchBar.selectAll();
searchBar.addActionListener(this);
createNodes(top);
tree = new JTree(top);
tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
tree.addTreeSelectionListener(this);
JScrollPane treeView = new JScrollPane(tree);
contentPane.add(treeView, "Center");
contentPane.add(okButton, "South");
searchPane.add(searchLabel, "West");
searchPane.add(searchBar, "Center");
contentPane.add(searchPane, "North");
contentPane.setOpaque(true);
frame.setContentPane(contentPane);
frame.pack();
frame.setVisible(true);
}
示例10: Client
import javax.swing.JTextField; //导入方法依赖的package包/类
public Client(String host)
{
super("Client");
chatServer = host; // set server to which this client connects
enterField = new JTextField(); // create enterField
enterField.setEditable(false);
enterField.addActionListener(
new ActionListener()
{
// send message to server
public void actionPerformed(ActionEvent event)
{
sendData(event.getActionCommand());
enterField.setText("");
}
}
);
add(enterField, BorderLayout.NORTH);
displayArea = new JTextArea(); // create displayArea
add(new JScrollPane(displayArea), BorderLayout.CENTER);
setSize(300, 150); // set size of window
setVisible(true); // show window
}
示例11: richiediNome
import javax.swing.JTextField; //导入方法依赖的package包/类
private void richiediNome() {
nome = null;
askNome = new JTextField();
JButton askNomeButton = new JButton(caricaImmagine("dominio/immagini/fatto.png"));
JLabel askNomeLabel = new JLabel(caricaImmagine("dominio/immagini/richiediNome.png"));
ActionListener action_nome_inserito = new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
nome = askNome.getText();
};
};
askNome.setFont(new Font("nome", 1, 40));
askNome.setBounds(this.getWidth()/2 - 125, 300, 250, 80);
askNomeButton.setBounds(this.getWidth()/2 - 100, 400, 200, 80);
askNomeLabel.setBounds(this.getWidth()/2 - 200, 100, 400, 80);
askNome.addActionListener(action_nome_inserito);
askNomeButton.addActionListener(action_nome_inserito);
sfondo.add(askNome);
sfondo.add(askNomeButton);
sfondo.add(askNomeLabel);
sfondo.repaint();
while(nome == null) {
pausa(100);
}
sfondo.removeAll();
sfondo.repaint();
fireViewEvent(new SetNome(nome));
}
示例12: createGui
import javax.swing.JTextField; //导入方法依赖的package包/类
@SuppressWarnings("nls")
private void createGui()
{
userQuery = new JTextField();
groupQuery = new JTextField();
final String searchText = CurrentLocale.get("com.dytech.edge.admin.helper.usergroupdialog.search");
userSearch = new JButton(searchText);
groupSearch = new JButton(searchText);
userQuery.addActionListener(this);
groupQuery.addActionListener(this);
userSearch.addActionListener(this);
groupSearch.addActionListener(this);
userModel = new DefaultListModel();
groupModel = new DefaultListModel();
userList = new JList(userModel);
groupList = new JList(groupModel);
tabs = new JTabbedPane();
tabs.addTab(CurrentLocale.get("com.dytech.edge.admin.helper.usergroupdialog.selectuser"),
createTab("user", userQuery, userSearch, userList));
tabs.addTab(CurrentLocale.get("com.dytech.edge.admin.helper.usergroupdialog.selectgroup"),
createTab("group", groupQuery, groupSearch, groupList));
setLayout(new GridLayout(1, 1));
add(tabs);
}
示例13: TreePanel
import javax.swing.JTextField; //导入方法依赖的package包/类
public TreePanel()
{
query = new JTextField();
query.addActionListener(this);
search = new JButton(CurrentLocale.get("searching.userGroupRole.executeQuery"));
search.addActionListener(this);
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout(5, 5));
panel
.add(new JLabel(CurrentLocale.get("com.tle.admin.recipients.browserfinder.groups")), BorderLayout.WEST);
panel.add(query, BorderLayout.CENTER);
panel.add(search, BorderLayout.EAST);
model = new DefaultTreeModel(null);
tree = new JTree(model);
setLayout(new BorderLayout(5, 5));
add(panel, BorderLayout.NORTH);
add(new JScrollPane(tree), BorderLayout.CENTER);
tree.addMouseListener(mouse);
tree.setShowsRootHandles(true);
tree.setRootVisible(false);
tree.addTreeSelectionListener(this);
}
示例14: CustomDialog
import javax.swing.JTextField; //导入方法依赖的package包/类
/** Creates the reusable dialog. */
public CustomDialog(Frame aFrame, String aWord, DialogDemo parent) {
super(aFrame, true);
dd = parent;
magicWord = aWord.toUpperCase();
setTitle("Quiz");
textField = new JTextField(10);
// Create an array of the text and components to be displayed.
String msgString1 = "What was Dr. SEUSS's real last name?";
String msgString2 = "(The answer is \"" + magicWord + "\".)";
Object[] array = { msgString1, msgString2, textField };
// Create an array specifying the number of dialog buttons
// and their text.
Object[] options = { btnString1, btnString2 };
// Create the JOptionPane.
optionPane = new JOptionPane(array, JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null, options, options[0]);
// Make this dialog display it.
setContentPane(optionPane);
// Handle window closing correctly.
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent we) {
/*
* Instead of directly closing the window, we're going to change
* the JOptionPane's value property.
*/
optionPane.setValue(new Integer(JOptionPane.CLOSED_OPTION));
}
});
// Ensure the text field always gets the first focus.
addComponentListener(new ComponentAdapter() {
public void componentShown(ComponentEvent ce) {
textField.requestFocusInWindow();
}
});
// Register an event handler that puts the text into the option pane.
textField.addActionListener(this);
// Register an event handler that reacts to option pane state changes.
optionPane.addPropertyChangeListener(this);
}
示例15: ScaleMapSizeDialog
import javax.swing.JTextField; //导入方法依赖的package包/类
/**
* Create a ScaleMapSizeDialog.
*
* @param freeColClient The {@code FreeColClient} for the game.
* @param frame The owner frame.
*/
public ScaleMapSizeDialog(final FreeColClient freeColClient, JFrame frame) {
super(freeColClient, frame);
/*
* FIXME: Extend this dialog. It should be possible to specify
* the sizes using percentages.
*
* Add a panel containing information about the scaling (old
* size, new size etc).
*/
MigPanel panel = new MigPanel(new MigLayout("wrap 1, center"));
JPanel widthPanel = new JPanel(new FlowLayout());
JPanel heightPanel = new JPanel(new FlowLayout());
String str;
oldMap = freeColClient.getGame().getMap();
str = Integer.toString(oldMap.getWidth());
inputWidth = new JTextField(str, COLUMNS);
str = Integer.toString(oldMap.getHeight());
inputHeight = new JTextField(str, COLUMNS);
JLabel widthLabel = Utility.localizedLabel("width");
widthLabel.setLabelFor(inputWidth);
JLabel heightLabel = Utility.localizedLabel("height");
heightLabel.setLabelFor(inputHeight);
widthPanel.setOpaque(false);
widthPanel.add(widthLabel);
widthPanel.add(inputWidth);
heightPanel.setOpaque(false);
heightPanel.add(heightLabel);
heightPanel.add(inputHeight);
panel.add(widthPanel);
panel.add(heightPanel);
panel.setSize(panel.getPreferredSize());
final ActionListener al = (ActionEvent ae) -> {
ScaleMapSizeDialog.this.checkFields();
};
inputWidth.addActionListener(al);
inputHeight.addActionListener(al);
final Dimension fake = null;
List<ChoiceItem<Dimension>> c = choices();
c.add(new ChoiceItem<>(Messages.message("ok"), fake).okOption());
c.add(new ChoiceItem<>(Messages.message("cancel"), fake)
.cancelOption().defaultOption());
initializeDialog(frame, DialogType.QUESTION, true, panel, null, c);
}