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


Java JFormattedTextField.addKeyListener方法代码示例

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


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

示例1: PHTextFieldNode

import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
public PHTextFieldNode( IntegerRange range ) {
    super();
    
    _range = new IntegerRange( range );
    
    _listeners = new ArrayList();
    
    EventHandler textFieldEventHandler = new EventHandler();
    
    JLabel phLabel = new JLabel( PHScaleStrings.LABEL_PH );
    phLabel.setFont( LABEL_FONT );
    
    _textField = new JFormattedTextField( "XX.XX" );
    _textField.setFont( VALUE_FONT );
    _textField.setColumns( VALUE_COLUMNS );
    _textField.setHorizontalAlignment( JTextField.RIGHT );
    _textField.addActionListener( textFieldEventHandler );
    _textField.addFocusListener( textFieldEventHandler );
    _textField.addKeyListener( textFieldEventHandler );
    
    JPanel valuePanel = new JPanel();
    valuePanel.setOpaque( false );
    EasyGridBagLayout valuePanelLayout = new EasyGridBagLayout( valuePanel );
    valuePanel.setLayout( valuePanelLayout );
    valuePanelLayout.addComponent( phLabel, 0, 0 );
    valuePanelLayout.addComponent( _textField, 0, 1 );
    PSwing valuePanelWrapper = new PSwing( valuePanel );
    
    addChild( valuePanelWrapper );
    
    // initialize
    setPH( range.getDefault() );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:34,代码来源:PHTextFieldNode.java

示例2: LaserPowerControl

import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
/**
 * Constructor.
 * 
 * @param powerRange
 * @param label
 * @param units
 * @param pattern
 * @param columns
 * @param wavelength
 * @param sliderSize
 * @param font
 */
public LaserPowerControl( DoubleRange powerRange, String label, String units, String pattern, int columns,
        double wavelength, Dimension sliderSize, Font font ) {
    super();
    
    _minPower = powerRange.getMin();
    _maxPower = powerRange.getMax();
  
    _listener = new EventHandler();
    _listenerList = new EventListenerList();
    
    Color color = VisibleColor.wavelengthToColor( wavelength );
    _intensitySlider = new IntensitySlider( color, IntensitySlider.HORIZONTAL, sliderSize );
    _intensitySlider.addChangeListener( _listener );
    
    _label = new JLabel( label );
    _label.setFont( font );
    
    _formattedTextField = new JFormattedTextField();
    _formattedTextField.setFont( font );
    _formattedTextField.setColumns( columns );
    _formattedTextField.setHorizontalAlignment( JTextField.RIGHT );
    _formattedTextField.addActionListener( _listener );
    _formattedTextField.addFocusListener( _listener );
    _formattedTextField.addKeyListener( _listener );
    
    _formatter = new DecimalFormat( pattern );
    
    _units = new JLabel( units );
    _units.setFont( font );
    
    // Opacity
    _intensitySlider.setOpaque( false );
    _units.setOpaque( false );
    
    // Default state
    _power = powerRange.getMin() - 1; // force an update
    setPower( powerRange.getDefault() );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:51,代码来源:LaserPowerControl.java

示例3: ConcentrationControlNode

import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
public ConcentrationControlNode( double min, double max ) {
    super();
    
    changeListeners = new ArrayList<ChangeListener>();
    
    sliderNode = new ConcentrationSliderNode( min, max );
    addChild( sliderNode );
    sliderNode.addChangeListener( new SliderListener() );
    
    textField = new JFormattedTextField( TEXTFIELD_FORMAT );
    textField.setFont( TEXTFIELD_FONT );
    textField.setValue( new Double( sliderNode.getValue() ) );
    textField.setHorizontalAlignment( JTextField.RIGHT );
    textField.setColumns( TEXTFIELD_COLUMNS );
    TextFieldListener textFieldListener = new TextFieldListener();
    textField.addActionListener( textFieldListener );
    textField.addFocusListener( textFieldListener );
    textField.addKeyListener( textFieldListener );
    
    JLabel unitsLabel = new JLabel( AABSStrings.UNITS_MOLES_PER_LITER );
    unitsLabel.setFont( UNITS_FONT );
    
    JPanel panel = new JPanel();
    panel.setOpaque( false );
    panel.add( textField );
    panel.add( unitsLabel );
    
    PSwing panelWrapper = new PSwing( panel );
    addChild( panelWrapper );
    
    // slider
    double xOffset = 0;
    double yOffset = 0;
    sliderNode.setOffset( xOffset, yOffset );
    // text field to the right of slider, vertically centered
    xOffset = sliderNode.getFullBoundsReference().getMaxX() + X_SPACING;
    yOffset = sliderNode.getFullBoundsReference().getCenterY() - ( panelWrapper.getFullBoundsReference().getHeight() / 2 );
    panelWrapper.setOffset( xOffset, yOffset );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:40,代码来源:ConcentrationControlNode.java

示例4: IntensityControl

import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
/**
 * Constructor.
 * 
 * @param size
 * @param font
 */
public IntensityControl( Dimension size, Font font ) {
    super();
    
    _listenerList = new EventListenerList();
    _eventSource = this;
    EventHandler listener = new EventHandler();
    
    _slider = new IntensitySlider( Color.RED, IntensitySlider.HORIZONTAL, size );
    _slider.addChangeListener( listener );
    
    _formattedTextField = new JFormattedTextField();
    _formattedTextField.setFont( font );
    _formattedTextField.setColumns( 3 );
    _formattedTextField.setHorizontalAlignment( JTextField.RIGHT );
    _formattedTextField.addActionListener( listener );
    _formattedTextField.addFocusListener( listener );
    _formattedTextField.addKeyListener( listener );
    
    _units = new JLabel( "%" );
    _units.setFont( font );
    
    // Opacity
    setOpaque( false );
    _slider.setOpaque( false );
    _units.setOpaque( false );
    
    // Layout
    EasyGridBagLayout layout = new EasyGridBagLayout( this );
    layout.setInsets( new Insets( 0, 0, 0, 3 ) ); // top, left, bottom, right
    this.setLayout( layout );
    layout.setAnchor( GridBagConstraints.WEST );
    int row = 0;
    int col = 0;
    layout.addComponent( _slider, row, col++ );
    layout.addComponent( _formattedTextField, row, col++ );
    layout.addComponent( _units, row, col++ );
    
    // Default state
    setValue( 0 );
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:47,代码来源:IntensityControl.java

示例5: AbstractValueControl

import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
/**
 * Constructor.
 *
 * @param slider
 * @param label            label that appears to the left of the value
 * @param textFieldPattern pattern used to format the text field (see DecimalFormat)
 * @param units            units that appear to the right of the value
 * @param layoutStrategy
 * @throws IllegalArgumentException
 */
public AbstractValueControl( AbstractSlider slider, String label, String textFieldPattern, String units, ILayoutStrategy layoutStrategy ) {
    super();

    _slider = slider;
    _slider.setPaintTicks( true ); // Needed to make the knob reasonably large, see #2979.

    _majorTickSpacing = _slider.getModelRange(); // default is major tick marks at min and max
    _minorTickSpacing = 0;
    _upDownArrowDelta = _slider.getModelRange() / 100;
    _slider.setUpDownArrowDelta( _upDownArrowDelta );

    _textFieldFormat = new DecimalFormat( textFieldPattern );
    _tickFormat = new DecimalFormat( textFieldPattern ); // use same format for ticks and textfield
    _majorTicksVisible = true; // major tick labels visible
    _minorTicksVisible = false; // minor tick labels are typically not visible
    _labelTable = null; // instantiated when addTickLabel is called
    _paintTickLabels = true;
    _signifyOutOfBounds = true;

    _notifyWhileAdjusting = true; // provide change notification while slider is dragging
    _isAdjusting = false;
    _font = new PhetFont();
    _listenerList = new EventListenerList();

    // Labels
    _valueLabel = new HTMLLabel( label );
    _unitsLabel = new HTMLLabel( units );

    // Textfield
    _textField = new JFormattedTextField( _textFieldFormat );
    _textField.setValue( new Double( _value ) );
    _textField.setHorizontalAlignment( JTextField.RIGHT );
    _textField.setColumns( textFieldPattern.length() );

    // Layout the components
    layoutStrategy.doLayout( this );

    // Listeners
    _sliderListener = new SliderListener();
    _slider.addChangeListener( _sliderListener );
    _slider.addMouseListener( _sliderListener );
    _textFieldListener = new TextFieldListener();
    _textField.addActionListener( _textFieldListener );
    _textField.addFocusListener( _textFieldListener );
    _textField.addKeyListener( _textFieldListener );

    updateTickLabels();

    _value = _slider.getModelMin() - 1; // force setValue to initalize the components
    setValue( slider.getModelValue() );

    _initialized = true;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:64,代码来源:AbstractValueControl.java

示例6: ReturnIFrame

import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
public ReturnIFrame() {
	super();
	setIconifiable(true);							// ���ô������С������������
	setClosable(true);								// ���ô���ɹرգ���������
	setTitle("��ӹ黹��Ϣ");						// ���ô�����⣭��������
	setBounds(100, 50, 500, 225);

	//������ͷͼƬ
	final JLabel logoLabel = new JLabel();
	ImageIcon readerAddIcon=CreateIcon.add("tback.jpg");
	logoLabel.setIcon(readerAddIcon);
	logoLabel.setOpaque(true);
	logoLabel.setBackground(Color.white);
	logoLabel.setPreferredSize(new Dimension(400, 60));
	getContentPane().add(logoLabel, BorderLayout.NORTH);

	//����һ�������������
	final JPanel panel = new JPanel();
	panel.setLayout(new FlowLayout());
	getContentPane().add(panel);

	//�������������Ƕ�����1,���ڷ��÷ǰ�ť���
	final JPanel panel_1 = new JPanel();
	final GridLayout gridLayout = new GridLayout(2, 2);
	gridLayout.setVgap(20);
	panel_1.setLayout(gridLayout);
	panel.add(panel_1);

	final JLabel label_2 = new JLabel();
	label_2.setText("���ļ�¼��ţ�");
	panel_1.add(label_2);
	id = new JTextField(10);
	id.setDocument(new MyDocument(256));
	panel_1.add(id);
	
	final JLabel label_3 = new JLabel();
	label_3.setText("�黹���ڣ�");
	panel_1.add(label_3);
	return_date = new JFormattedTextField();
	return_date.setValue("XXXX-XX-XX");
	return_date.addKeyListener(new DateListener());
	panel_1.add(return_date);
	
	//����������Ƕ��һ�����ڷ��Ű�ť�����
	final JPanel panel_2 = new JPanel();
	panel_2.setPreferredSize(new Dimension(450, 100));
	panel.add(panel_2);
	
	final JRadioButton radioButton1 = new JRadioButton();

	//�����������
	final JButton submit = new JButton();
	panel_2.add(submit);
	submit.setText("�ύ");
	submit.addActionListener((ActionListener) new ButtonAddListener(radioButton1));
	
	//�����������
	final JButton back = new JButton();
	panel_2.add(back);
	back.setText("����");
	back.addActionListener(new CloseActionListener());

	setVisible(true);
}
 
开发者ID:GooZy,项目名称:LibraryManagementSystem,代码行数:65,代码来源:ReturnIFrame.java


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