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


Java JTextField.addFocusListener方法代码示例

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


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

示例1: SpecialkeyPanel

import javax.swing.JTextField; //导入方法依赖的package包/类
/** Creates new form SpecialkeyPanel */
public SpecialkeyPanel(final Popupable parent, JTextField target) {
    this.parent = parent;
    this.target = target;
    initComponents();

    target.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent e) {
            parent.hidePopup();
        }
    });

    downButton.addActionListener(this);
    enterButton.addActionListener(this);
    escButton.addActionListener(this);
    leftButton.addActionListener(this);
    rightButton.addActionListener(this);
    tabButton.addActionListener(this);
    upButton.addActionListener(this);
    wheelUpButton.addActionListener(this);
    wheelDownButton.addActionListener(this);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:SpecialkeyPanel.java

示例2: actionPerformed

import javax.swing.JTextField; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent ae) {
    currentActiveItem = this;
    
    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,代码行数:13,代码来源:ConfigurationsComboModel.java

示例3: 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

示例4: 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:max6cn,项目名称:jmt,代码行数:21,代码来源:DefaultsEditor.java

示例5: 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

示例6: buildFields

import javax.swing.JTextField; //导入方法依赖的package包/类
/**
 * 
 */
private void buildFields() {
	Vector properties = component.getProperties().getAllProperties();
	GridLayout layout = new GridLayout(properties.size(),2,10,10);
	int cells = 0;
	
	Iterator i = properties.iterator();
	JPanel fieldsPane = new JPanel(layout);
	fieldsPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
	
	while (i.hasNext()) {
		try {
			InteractiveProperty property = (InteractiveProperty) i.next();
			
			final JTextField field = new JTextField(property.toString());
			field.addKeyListener(new KeyAdapter() {
				public void keyReleased(KeyEvent e) {
					if (e.getKeyCode() == KeyEvent.VK_ENTER) {
						applyChanges();
					}
					else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
						cancelChanges();
					}
				}
			});
			field.addFocusListener(new FocusAdapter() {
				
				public void focusGained(FocusEvent evt) {
					String text = field.getText();
					field.setSelectionStart(0);
					field.setSelectionEnd(text.length());
				}
			});
			field.setMaximumSize(new Dimension(150,30));
			fields.put(property,field);
			
			fieldsPane.add(new JLabel(property.getName()));
			fieldsPane.add(field);
			
			cells++;
		} catch (ClassCastException exc) {
			/* 
			 * caught to be ignored, so that non-interactive properties
			 * won't be shown in the GUI
			 */
		}
	}
	this.setSize(200,cells * CELL_HEIGHT);
	getContentPane().add(fieldsPane,BorderLayout.CENTER);
}
 
开发者ID:guilhebl,项目名称:routerapp,代码行数:53,代码来源:PropertyInteractionDialog.java

示例7: addLine

import javax.swing.JTextField; //导入方法依赖的package包/类
/** Create a single-line entry box with the specified name, label,
 *  default value, and background color.  To control the width of
 *  the box, call setTextWidth() first.
 *  @param name The name used to identify the entry (when accessing
 *   the entry).
 *  @param label The label to attach to the entry.
 *  @param defaultValue Default value to appear in the entry box.
 *  @param background The background color.
 */
public void addLine(
        String name,
        String label,
        String defaultValue,
        Color background) {
    JLabel lbl = new JLabel(label + ": ");
    lbl.setBackground(_background);
    JTextField entryBox = new JTextField(defaultValue, _width);
    entryBox.setBackground(background);
    _addPair(name, lbl, entryBox, entryBox);

    // 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));
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:38,代码来源:Query.java

示例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;
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:31,代码来源:Query.java

示例9: QueryFileChooser

import javax.swing.JTextField; //导入方法依赖的package包/类
public QueryFileChooser(
        String name,
        String defaultName,
        URI base,
        File startingDirectory,
        Color background) {
    super(BoxLayout.X_AXIS);
    _base = base;
    _startingDirectory = startingDirectory;
    _entryBox = new JTextField(defaultName, _width);
    _entryBox.setBackground(background);
    JButton button = new JButton("Browse");
    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;
}
 
开发者ID:OpenDA-Association,项目名称:OpenDA,代码行数:35,代码来源:Query.java

示例10: 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

示例11: 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

示例12: NameChangeSupport

import javax.swing.JTextField; //导入方法依赖的package包/类
public NameChangeSupport(JTextField control) {
    this.control = control;
    control.getDocument().addDocumentListener(this);
    control.addFocusListener(this);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:6,代码来源:NameChangeSupport.java

示例13: FocusAdapter

import javax.swing.JTextField; //导入方法依赖的package包/类
public FocusAdapter(String targetToken, JTextField textField) {
    this.targetToken = targetToken;
    textField.addFocusListener(this);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:5,代码来源:NewConnectionPanel.java

示例14: initToolbarWest

import javax.swing.JTextField; //导入方法依赖的package包/类
private void initToolbarWest(JToolBar toolbar, ActionListener outputListener, boolean nbOutputComponent) {

        if (!nbOutputComponent) {
            JButton[] btns = getEditButtons();
            for (JButton btn : btns) {
                if (btn != null) {
                    toolbar.add(btn);
                }
            }
        }

        toolbar.addSeparator(new Dimension(10, 10));

        //add refresh button
        URL url = getClass().getResource(IMG_PREFIX + "refresh.png"); // NOI18N
        refreshButton = new JButton(new ImageIcon(url));
        refreshButton.setToolTipText(NbBundle.getMessage(DataViewUI.class, "TOOLTIP_refresh"));
        refreshButton.addActionListener(outputListener);
        processButton(refreshButton);

        toolbar.add(refreshButton);

        //add limit row label
        limitRow = new JLabel(NbBundle.getMessage(DataViewUI.class, "LBL_max_rows"));
        limitRow.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 8));
        toolbar.add(limitRow);

        //add refresh text field
        refreshField = new JTextField(5);
        refreshField.setMinimumSize(refreshField.getPreferredSize());
        refreshField.setMaximumSize(refreshField.getPreferredSize());
        refreshField.addFocusListener(new FocusAdapter() {
            @Override
            public void focusGained(FocusEvent e) {
                refreshField.selectAll();
            }
        });
        refreshField.addActionListener(outputListener);
        toolbar.add(refreshField);
        toolbar.addSeparator(new Dimension(10, 10));

        JLabel fetchedRowsNameLabel = new JLabel(NbBundle.getMessage(DataViewUI.class, "LBL_fetched_rows"));
        fetchedRowsNameLabel.getAccessibleContext().setAccessibleName(NbBundle.getMessage(DataViewUI.class, "LBL_fetched_rows"));
        fetchedRowsNameLabel.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
        toolbar.add(fetchedRowsNameLabel);
        fetchedRowsLabel = new JLabel();
        toolbar.add(fetchedRowsLabel);

        toolbar.addSeparator(new Dimension(10, 10));
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:51,代码来源:DataViewUI.java

示例15: TickPanel

import javax.swing.JTextField; //导入方法依赖的package包/类
public TickPanel(String value, int type) {
  super(new GridBagLayout());
  set(value);

  panelType = type;

  GridBagConstraints c = new GridBagConstraints();
  c.fill = GridBagConstraints.BOTH;
  c.ipadx = 1;
  c.weightx = 0.0;
  c.gridx = 0;
  c.gridy = 0;

  Dimension minSize;

  if (panelType == TICKS_VAL || panelType == TICKS_VALMAX) {
    valField = new JTextField(Integer.toString(numTicks));
    minSize = valField.getMinimumSize();
    minSize.width = 24;
    valField.setMinimumSize(minSize);
    valField.setPreferredSize(minSize);
    valField.addActionListener(this);
    valField.addFocusListener(this);
    add(valField, c);
    ++c.gridx;
  }
  if (panelType == TICKS_MAX || panelType == TICKS_VALMAX) {
    maxField = new JTextField(Integer.toString(maxTicks));
    minSize = maxField.getMinimumSize();
    minSize.width = 24;
    maxField.setMinimumSize(minSize);
    maxField.setPreferredSize(minSize);
    maxField.addActionListener(this);
    maxField.addFocusListener(this);
    if (panelType == TICKS_VALMAX) {
      add(new JLabel("/"), c);
      ++c.gridx;
    }
    add(maxField, c);
    ++c.gridx;
  }

  ticks = new TickLabel(numTicks, maxTicks, panelType);
  ticks.addActionListener(this);
  c.weightx = 1.0;
  add(ticks, c);
  doLayout();
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:49,代码来源:PropertySheet.java


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