当前位置: 首页>>代码示例>>Java>>正文


Java JTextField.addKeyListener方法代码示例

本文整理汇总了Java中javax.swing.JTextField.addKeyListener方法的典型用法代码示例。如果您正苦于以下问题:Java JTextField.addKeyListener方法的具体用法?Java JTextField.addKeyListener怎么用?Java JTextField.addKeyListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.JTextField的用法示例。


在下文中一共展示了JTextField.addKeyListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: Busqueda

import javax.swing.JTextField; //导入方法依赖的package包/类
public Busqueda(Connection conn, JFrameJTable principal, String sql, char QuienEs) {
	setIconImage(Toolkit.getDefaultToolkit().getImage(Busqueda.class.getResource("/biblioteca/images/book.png")));
	this.QuienEs=QuienEs;
	this.conn=conn;
	this.principal=principal;
	this.principal.setEnabled(false);
	setTitle("B�squeda");
	
	setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	setBounds(100, 100, 492, 370);
	contentPane = new JPanel();
	contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
	setContentPane(contentPane);
	contentPane.setLayout(null);
	
	txtUsuario = new JTextField();
	txtUsuario.setBounds(10, 33, 328, 23);
	contentPane.add(txtUsuario);
	txtUsuario.setColumns(10);
	txtUsuario.addKeyListener(this);
	
	btnBuscar = new JButton("Buscar");
	btnBuscar.setBounds(357, 32, 109, 23);
	contentPane.add(btnBuscar);
	btnBuscar.addActionListener(this);
	
	table = new PanelJtable(conn,sql,this);
	table.setBounds(10, 78, 456, 242);
	contentPane.add(table);
	
	addWindowListener(this);
	setVisible(true);
	setLocationRelativeTo(null);
}
 
开发者ID:JuandeLS3,项目名称:Library-app,代码行数:35,代码来源:Busqueda.java

示例2: 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;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:ButtonCellEditor.java

示例3: startRename

import javax.swing.JTextField; //导入方法依赖的package包/类
private void startRename() {
	
	// init the text box
	final JTextField text = new JTextField();
	text.setText(m_reference.getNamableName());
	text.setPreferredSize(new Dimension(360, text.getPreferredSize().height));
	text.addKeyListener(new KeyAdapter() {
		@Override
		public void keyPressed(KeyEvent event) {
			switch (event.getKeyCode()) {
				case KeyEvent.VK_ENTER:
					finishRename(text, true);
				break;
				
				case KeyEvent.VK_ESCAPE:
					finishRename(text, false);
				break;
			}
		}
	});
	
	// find the label with the name and replace it with the text box
	JPanel panel = (JPanel)m_infoPanel.getComponent(0);
	panel.remove(panel.getComponentCount() - 1);
	panel.add(text);
	text.grabFocus();
	text.selectAll();
	
	redraw();
}
 
开发者ID:cccssw,项目名称:enigma-vk,代码行数:31,代码来源:Gui.java

示例4: addTextAreaToColumn

import javax.swing.JTextField; //导入方法依赖的package包/类
private void addTextAreaToColumn() {
	//Create the ComboBox and add the line blocks to it
	JTextField textArea = new JTextField();
	
	//Add a listener to the ComboBox, add stop when state changes
	textArea.addKeyListener(new KeyAdapter() {
		@Override
		public void keyReleased(KeyEvent e) {
			int row = table.getSelectedRow();
			String timeToDwell = textArea.getText();
			
			if(SimTime.isValid(timeToDwell) && row>=0) {
				schedule.addStop(row, new SimTime(timeToDwell));
				fireScheduleChanged();
			}
		}
	});

	//Put the TextArea into the JTable cell
	DefaultCellEditor textAreaEditor = new DefaultCellEditor(textArea);
	this.getColumnModel().getColumn(1).setCellEditor(textAreaEditor);
	
	//Add a tooltip
    DefaultTableCellRenderer textAreaRenderer = new DefaultTableCellRenderer();
    textAreaRenderer.setToolTipText("Type time to spend at the station");
    this.getColumnModel().getColumn(1).setCellRenderer(textAreaRenderer);
}
 
开发者ID:kevingilboy,项目名称:COE1186,代码行数:28,代码来源:ScheduleJTable.java

示例5: actionPerformed

import javax.swing.JTextField; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent ae) {
    JComboBox combo = (JComboBox) ae.getSource();
    combo.setEditable(true);
    JTextField editorComponent = (JTextField) combo.getEditor().getEditorComponent();
    editorComponent.addFocusListener(this);
    editorComponent.addKeyListener(this);
    combo.setSelectedItem(lastSelected);
    combo.addPopupMenuListener(this);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:ConfigurationsComboModel.java

示例6: AutoCompletionComboBoxEditor

import javax.swing.JTextField; //导入方法依赖的package包/类
public AutoCompletionComboBoxEditor(ComboBoxEditor editor) {
	if ((editor.getEditorComponent() instanceof JTextField)) {
		this.editor = editor;
		editorComponent = (JTextField) editor.getEditorComponent();
		editorComponent.getDocument().addDocumentListener(docListener);
		editorComponent.addKeyListener(new KeyAdapter() {

			@Override
			public void keyPressed(KeyEvent e) {
				if (e.getKeyCode() == KeyEvent.VK_ENTER) {
					setSelectedItem(editorComponent.getText());
					actionPerformed(new ActionEvent(this, 0, "editingStoped"));
					e.consume();
				} else if (e.getKeyCode() == KeyEvent.VK_TAB) {
					if (isPopupVisible()) {
						hidePopup();
					} else {
						showPopup();
					}
					e.consume();
				} else {
					super.keyPressed(e);
				}
			}
		});
	} else {
		throw new IllegalArgumentException("Only JTextField allowed as editor component");
	}
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:30,代码来源:AutoCompletionComboBox.java

示例7: makeGUIControl

import javax.swing.JTextField; //导入方法依赖的package包/类
@Override
public JComponent makeGUIControl() {

	final JPanel pan = new JPanel();
	pan.setAlignmentX(Component.LEFT_ALIGNMENT);
	pan.setLayout(new BoxLayout(pan, BoxLayout.X_AXIS));

	final JLabel label = new JLabel(getName());
	label.setToolTipText(
		"<html>" + toString() + "<br>" + getDescription() + "<br>Enter value or use mouse wheel or arrow keys to change value.");
	pan.add(label);

	final JTextField tf = new JTextField();
	tf.setText(Integer.toString(get()));
	tf.setPreferredSize(prefDimensions);
	tf.setMaximumSize(maxDimensions);
	SPIConfigIntActions actionListeners = new SPIConfigIntActions(this);
	tf.addActionListener(actionListeners);
	tf.addFocusListener(actionListeners);
	tf.addKeyListener(actionListeners);
	tf.addMouseWheelListener(actionListeners);
	pan.add(tf);
	setControl(tf);
	addObserver(biasgen);	// This observer is responsible for sending data to hardware
	addObserver(this);		// This observer is responsible for GUI update. It calls the updateControl() method
	return pan;
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:28,代码来源:SPIConfigInt.java

示例8: addProbability

import javax.swing.JTextField; //导入方法依赖的package包/类
/**
 * Add a probability to an interval Panel If the probability is for
 * interval B the value is displayed as 1-probability
 * 
 * @param intervalPanel
 *            the intervalPanel
 * @param intervalA
 *            if the probability is for interval A or B
 */
protected void addProbability(Container intervalPanel, boolean intervalA) {
	JLabel probLabel = new JLabel(PROBABILITY);
	JTextField probValue = new JTextField();
	Double probability = (Double) current.getParameter(0).getValue();

	// If the interval is interval A display value directly
	// Otherwise display 1-probability
	if (intervalA) {
		probValue.setName(PROBABILITY_INTERVAL_A);
	} else {
		probability = new Double(1 - probability.doubleValue());
		probValue.setName(PROBABILITY_INTERVAL_B);
	}
	probValue.setText(probability.toString());
	probLabel.setLabelFor(probValue);

	probValue.addFocusListener(new ProbabilityAdapter());
	probValue.addKeyListener(new ProbabilityAdapter());

	GridBagConstraints c = new GridBagConstraints();
	c.gridwidth = GridBagConstraints.RELATIVE; // next-to-last
	c.fill = GridBagConstraints.NONE; // reset to default
	c.weightx = 0.0; // reset to default
	c.weighty = 1.0;
	intervalPanel.add(probLabel, c);

	c.gridwidth = GridBagConstraints.REMAINDER; // end row
	c.fill = GridBagConstraints.HORIZONTAL;
	c.weightx = 1.0;
	c.weighty = 1.0;
	intervalPanel.add(probValue, c);
}
 
开发者ID:max6cn,项目名称:jmt,代码行数:42,代码来源:DistributionsEditor.java

示例9: createAndShowGUI

import javax.swing.JTextField; //导入方法依赖的package包/类
static void createAndShowGUI() {
    Frame frame = new Frame();
    frame.setSize(300, 300);
    Panel panel = new Panel(new BorderLayout());
    JTextField textField = new JTextField();
    textField.addKeyListener(new DeadKeyListener());
    panel.add(textField, BorderLayout.CENTER);
    frame.add(panel);
    frame.setVisible(true);
    toolkit.realSync();

    textField.requestFocusInWindow();
    toolkit.realSync();

}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:16,代码来源:DeadKeyMacOSXInputText.java

示例10: addInputString

import javax.swing.JTextField; //导入方法依赖的package包/类
/**
 * Adds an input field to insert a String
 * @param text text to be shown on a label
 * @param property property to be changed in Defaults
 * @param cont container where input field must be added
 */
protected void addInputString(String text, String property, Container cont) {
	JLabel label = new JLabel(text + ":");
	JTextField field = new JTextField(10);
	field.setName(property);
	label.setLabelFor(field);
	field.setText(Defaults.get(property));
	// Sets maximum size to minimal one, otherwise springLayout will stretch this
	field.setMaximumSize(new Dimension(field.getMaximumSize().width, field.getMinimumSize().height));
	field.addKeyListener(stringListener);
	field.addFocusListener(stringListener);
	registeredStringListener.add(field);
	cont.add(label);
	cont.add(field);
}
 
开发者ID:HOMlab,项目名称:QN-ACTR-Release,代码行数:21,代码来源:DefaultsEditor.java

示例11: addProbability

import javax.swing.JTextField; //导入方法依赖的package包/类
/**
 * Add a probability to an interval Panel
 * If the probability is for interval B the value is displayed as 1-probability
 * @param intervalPanel the intervalPanel
 * @param intervalA if the probability is for interval A or B
 */
protected void addProbability(Container intervalPanel, boolean intervalA) {

	JLabel probLabel = new JLabel(PROBABILITY);
	JTextField probValue = new JTextField();
	Double probability = (Double) current.getParameter(0).getValue();

	//If the interval is interval A display value directly
	//Otherwise display 1-probability
	if (intervalA) {
		probValue.setName(PROBABILITY_INTERVAL_A);
	} else {
		probability = new Double(1 - probability.doubleValue());
		probValue.setName(PROBABILITY_INTERVAL_B);
	}
	probValue.setText(probability.toString());
	probLabel.setLabelFor(probValue);

	probValue.addFocusListener(new ProbabilityAdapter());
	probValue.addKeyListener(new ProbabilityAdapter());

	GridBagConstraints c = new GridBagConstraints();
	c.gridwidth = GridBagConstraints.RELATIVE; // next-to-last
	c.fill = GridBagConstraints.NONE; // reset to default
	c.weightx = 0.0; // reset to default
	c.weighty = 1.0;
	intervalPanel.add(probLabel, c);

	c.gridwidth = GridBagConstraints.REMAINDER; // end row
	c.fill = GridBagConstraints.HORIZONTAL;
	c.weightx = 1.0;
	c.weighty = 1.0;
	intervalPanel.add(probValue, c);

}
 
开发者ID:HOMlab,项目名称:QN-ACTR-Release,代码行数:41,代码来源:DistributionsEditor.java

示例12: GuiPayloadField

import javax.swing.JTextField; //导入方法依赖的package包/类
private GuiPayloadField(FieldVO fieldVO, FieldVO superfieldVO) {

			this.isSubfield = (superfieldVO != null);
			this.superFieldVO = superfieldVO;
			this.fieldVO = fieldVO.getInstanceCopy();
			this.fieldVO.setFieldList(new ArrayList<FieldVO>());
			
			if (isSubfield)
				superFieldVO.getFieldList().add(this.fieldVO);
			else
				messageVO.getFieldList().add(this.fieldVO);
			
			ckBox = new JCheckBox();
			txtType = new JTextField();
			txtLength = new JTextField();
			txtValue = new JTextField();
			subfieldList = new ArrayList<GuiPayloadField>();
			
			lblFieldNum = new JLabel(fieldVO.getBitNum().toString());
			lblFieldName = new JLabel(fieldVO.getName());
			lblType = new JLabel(fieldVO.getType().toString());
			lblDynamic = new JLabel();
			lblDynamic.setIcon(new ImageIcon(PnlGuiPayload.class.getResource("/resource/search.png")));
			lblDynamic.setToolTipText(fieldVO.getDynaCondition());

			lineNum = numLines;
			numLines++;
			
			ckBox.setBounds(10, 10 + (lineNum * 25), 22, 22);
			lblFieldNum.setBounds(40, 10 + (lineNum * 25), 50, 22);
			lblFieldName.setBounds(80, 10 + (lineNum * 25), 100, 22);
			lblType.setBounds(470, 10 + (lineNum * 25), 100, 22);
			lblDynamic.setBounds(600, 10 + (lineNum * 25), 50, 22);
			
			if (fieldVO.getType() == TypeEnum.ALPHANUMERIC) {
				txtValue.setBounds(190, 10 + (lineNum * 25), 260, 22);
			}
			else if (fieldVO.getType() == TypeEnum.TLV) {
				txtType.setBounds(190, 10 + (lineNum * 25), 80, 22);
				txtLength.setBounds(280, 10 + (lineNum * 25), 80, 22);
				txtValue.setBounds(370, 10 + (lineNum * 25), 80, 22);
				
				pnlFields.add(txtType);
				pnlFields.add(txtLength);
			}
			
			if (!isSubfield)
				pnlFields.add(ckBox);
				
			pnlFields.add(lblFieldNum);
			pnlFields.add(lblFieldName);
			pnlFields.add(txtValue);
			pnlFields.add(lblType);

			txtType.addKeyListener(saveFieldPayloadAction);
			txtLength.addKeyListener(saveFieldPayloadAction);
			txtValue.addKeyListener(saveFieldPayloadAction);
			
			if (!fieldVO.getDynaCondition().equals("") && !fieldVO.getDynaCondition().equals("true"))
				pnlFields.add(lblDynamic);
			
			if (fieldVO.getDynaCondition().equals("true")) {
				ckBox.setSelected(true);
				ckBox.setEnabled(false);
				ckBoxClick(ckBox);
				
				setEnabled(true);
			}
			else {
				ckBox.addActionListener(new ActionListener() {
					@Override
					public void actionPerformed(ActionEvent e) {
						ckBoxClick((JCheckBox) e.getSource());
						saveFieldValue();
					}
				});
				
				setEnabled(false);
			}
		}
 
开发者ID:adelbs,项目名称:ISO8583,代码行数:81,代码来源:PayloadMessageConfig.java

示例13: AccountTransferDialog

import javax.swing.JTextField; //导入方法依赖的package包/类
/**
 * Set up and show the dialog. The first Component argument determines which
 * frame the dialog depends on; it should be a component in the dialog's
 * controlling frame. The second Component argument should be null if you
 * want the dialog to come up with its left corner in the center of the
 * screen; otherwise, it should be the component on top of which the dialog
 * should appear.
 */

public AccountTransferDialog(Component frameComp, Component locationComp,
		String title,  Object[] brokers,I_TickerManager tickerManager) {
	super(frameComp, locationComp, title, tickerManager);

	
	brokerList = new JComboBox(brokers);
	brokerList.setEditable(true);
	brokerList.setSelectedIndex(0);
	
	newBrokerField = new JTextField(FIELD_LEN);
	newBrokerField.setEditable(true);
	newBrokerField.setText("");		
	newBrokerField.addKeyListener(this);
	
	dateFieldLabel = new JLabel("Siirtopäivä: ");
	dateFieldLabel.setLabelFor(dateChooser);
	
	brokerFieldLabel = new JLabel("Vanha välittäjä: ");
	brokerFieldLabel.setLabelFor(brokerList);
	
	newBrokerFieldLabel = new JLabel("Uusi välittäjä: ");
	newBrokerFieldLabel.setLabelFor(newBrokerField);
	
	init(getDialogLabels(), getDialogComponents());
}
 
开发者ID:skarna1,项目名称:javaportfolio,代码行数:35,代码来源:AccountTransferDialog.java

示例14: ConsultarPrestamo

import javax.swing.JTextField; //导入方法依赖的package包/类
public ConsultarPrestamo(Connection conn, JFrameJTable principal, String sql) {
	setIconImage(Toolkit.getDefaultToolkit().getImage(ConsultarPrestamo.class.getResource("/biblioteca/images/book.png")));
	this.conn=conn;
	this.principal=principal;
	this.principal.setEnabled(false);
	setTitle("Consultar pr�stamo");
	
	setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
	setBounds(100, 100, 703, 472);
	contentPane = new JPanel();
	contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
	setContentPane(contentPane);
	contentPane.setLayout(null);
	
	opciones=new CheckboxGroup();
	tipo=new Checkbox("Tipo", opciones, false);
	usuario=new Checkbox("Usuario",opciones,true);
	tipo.addItemListener(this);
	usuario.addItemListener(this);
	tipo.setBounds(500, 20, 62, 23);
	usuario.setBounds(500, 49, 62, 23);
	contentPane.add(usuario);
	contentPane.add(tipo);
	
	txtUsuario = new JTextField();
	txtUsuario.setBounds(10, 33, 465, 23);
	contentPane.add(txtUsuario);
	txtUsuario.setColumns(10);
	txtUsuario.addKeyListener(this);
	
	btnBuscar = new JButton("Buscar");
	btnBuscar.setBounds(568, 33, 109, 23);
	contentPane.add(btnBuscar);
	btnBuscar.addActionListener(this);
	
	table = new PanelJtable(conn,sql,this);
	table.setBounds(10, 82, 667, 340);
	contentPane.add(table);
	
	addWindowListener(this);
	setVisible(true);
	setLocationRelativeTo(null);
}
 
开发者ID:JuandeLS3,项目名称:Library-app,代码行数:44,代码来源:ConsultarPrestamo.java

示例15: buildEditor

import javax.swing.JTextField; //导入方法依赖的package包/类
private JPanel buildEditor(CharacterType character)
{
    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("ID"), gbc);

    gbc.gridx++;
    idTextField = new JTextField(character.getId());
    idTextField.addActionListener(this);
    idTextField.addKeyListener(new KeyAdapter() {
        @Override
        public void keyTyped(KeyEvent e) {
            char keyChar = e.getKeyChar();
            if (Character.isUpperCase(keyChar)) {
                e.setKeyChar(Character.toLowerCase(keyChar));
            }
        }
    });
    editor.add(idTextField, gbc);

    gbc.gridx = 0;
    gbc.gridy++;
    editor.add(new JLabel("Titel"), gbc);

    gbc.gridx++;
    titleTextField = new JTextField(character.getTitle());
    titleTextField.addActionListener(this);
    editor.add(titleTextField, gbc);

    gbc.gridy++;
    imageCheckbox = new JCheckBox("Bild anzeigen", character.getImage().equals("yes"));
    imageCheckbox.addActionListener(this);
    editor.add(imageCheckbox, gbc);

    gbc.gridy++;
    gbc.gridx = 0;
    gbc.gridwidth = 2;
    gbc.insets.top = 20;
    saveButton = new JButton("Übernehmen");
    saveButton.addActionListener(this);
    editor.add(saveButton, gbc);

    gbc.gridy++;
    gbc.insets.top = 0;
    removeButton = new MetalGradientButton("Charakter entfernen");
    removeButton.addActionListener(this);
    removeButton.setBackground(Color.RED.darker());
    removeButton.setEnabled(canRemove);
    editor.add(removeButton, gbc);

    return editor;
}
 
开发者ID:Entwicklerpages,项目名称:school-game,代码行数:60,代码来源:CharacterEditorPanel.java


注:本文中的javax.swing.JTextField.addKeyListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。