本文整理汇总了Java中javax.swing.JFormattedTextField.setValue方法的典型用法代码示例。如果您正苦于以下问题:Java JFormattedTextField.setValue方法的具体用法?Java JFormattedTextField.setValue怎么用?Java JFormattedTextField.setValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFormattedTextField
的用法示例。
在下文中一共展示了JFormattedTextField.setValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getImageSizePanel
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
private JPanel getImageSizePanel() {
JPanel imageSizePanel = new JPanel();
imageSizePanel.setLayout(new GridLayout(1, 4));
NumberFormat format = NumberFormat.getInstance();
format.setGroupingUsed(false);
NumberFormatter formatter = new NumberFormatter(format);
formatter.setValueClass(Integer.class);
formatter.setMinimum(0);
formatter.setMaximum(Integer.MAX_VALUE);
formatter.setCommitsOnValidEdit(true);
widthTF = new JFormattedTextField(formatter);
widthTF.setValue(1200);
addFocusListener(widthTF);
heightTF = new JFormattedTextField(formatter);
heightTF.setValue(1000);
addFocusListener(heightTF);
imageSizePanel.add(new JLabel(" Width:"));
imageSizePanel.add(widthTF);
imageSizePanel.add(new JLabel(" Height:"));
imageSizePanel.add(heightTF);
return imageSizePanel;
}
示例2: getImageSizePanel
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
private JPanel getImageSizePanel() {
JPanel imageSizePanel = new JPanel();
imageSizePanel.setLayout(new GridLayout(1, 4));
NumberFormat format = NumberFormat.getInstance();
format.setGroupingUsed(false);
NumberFormatter formatter = new NumberFormatter(format);
formatter.setValueClass(Integer.class);
formatter.setMinimum(0);
formatter.setMaximum(Integer.MAX_VALUE);
formatter.setCommitsOnValidEdit(true);
widthTF = new JFormattedTextField(formatter);
widthTF.setValue(1200);
widthTF.addFocusListener(FOCUS_LISTENER);
heightTF = new JFormattedTextField(formatter);
heightTF.setValue(1000);
heightTF.addFocusListener(FOCUS_LISTENER);
imageSizePanel.add(new JLabel(" Width:"));
imageSizePanel.add(widthTF);
imageSizePanel.add(new JLabel(" Height:"));
imageSizePanel.add(heightTF);
return imageSizePanel;
}
示例3: setupIntegerFieldTrackingValue
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
/**
* Sets integer number format to JFormattedTextField instance,
* sets value of JFormattedTextField instance to object's field value,
* synchronizes object's field value with the value of JFormattedTextField instance.
*
* @param textField JFormattedTextField instance
* @param owner an object whose field is synchronized with {@code textField}
* @param property object's field name for synchronization
*/
public static void setupIntegerFieldTrackingValue(final JFormattedTextField textField,
final InspectionProfileEntry owner,
final String property) {
NumberFormat formatter = NumberFormat.getIntegerInstance();
formatter.setParseIntegerOnly(true);
textField.setFormatterFactory(new DefaultFormatterFactory(new NumberFormatter(formatter)));
textField.setValue(getPropertyValue(owner, property));
final Document document = textField.getDocument();
document.addDocumentListener(new DocumentAdapter() {
@Override
public void textChanged(DocumentEvent e) {
try {
textField.commitEdit();
setPropertyValue(owner, property,
((Number) textField.getValue()).intValue());
} catch (ParseException e1) {
// No luck this time
}
}
});
}
示例4: GridEditPanel
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
public GridEditPanel(int rasterSize) {
JLabel lblSize = new JLabel("size (px)");
lblSize.setFont(Program.TEXT_FONT.deriveFont(Font.BOLD).deriveFont(10f));
textField = new JFormattedTextField(NumberFormat.getIntegerInstance());
textField.setText("16");
textField.setFont(Program.TEXT_FONT.deriveFont(10f));
textField.setColumns(10);
textField.setValue(rasterSize);
GroupLayout groupLayout = new GroupLayout(this);
groupLayout.setHorizontalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addContainerGap()
.addComponent(lblSize, GroupLayout.PREFERRED_SIZE, 44, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(textField, GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE)
.addGap(34)));
groupLayout.setVerticalGroup(
groupLayout.createParallelGroup(Alignment.LEADING)
.addGroup(groupLayout.createSequentialGroup()
.addContainerGap()
.addGroup(groupLayout.createParallelGroup(Alignment.BASELINE)
.addComponent(lblSize, GroupLayout.PREFERRED_SIZE, 13, GroupLayout.PREFERRED_SIZE)
.addComponent(textField, GroupLayout.PREFERRED_SIZE, 19, GroupLayout.PREFERRED_SIZE))
.addContainerGap(46, Short.MAX_VALUE)));
setLayout(groupLayout);
}
示例5: IntegerEditor
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
public IntegerEditor(int min, int max) {
super(new JFormattedTextField());
ftf = (JFormattedTextField) getComponent();
minimum = new Integer(min);
maximum = new Integer(max);
// Set up the editor for the integer cells.
integerFormat = NumberFormat.getIntegerInstance();
NumberFormatter intFormatter = new NumberFormatter(integerFormat);
intFormatter.setFormat(integerFormat);
intFormatter.setMinimum(minimum);
intFormatter.setMaximum(maximum);
ftf.setFormatterFactory(new DefaultFormatterFactory(intFormatter));
ftf.setValue(minimum);
ftf.setHorizontalAlignment(JTextField.TRAILING);
ftf.setFocusLostBehavior(JFormattedTextField.PERSIST);
// React when the user presses Enter while the editor is
// active. (Tab is handled as specified by
// JFormattedTextField's focusLostBehavior property.)
ftf.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "check");
ftf.getActionMap().put("check", new AbstractAction() {
public void actionPerformed(ActionEvent e) {
if (!ftf.isEditValid()) { // The text is invalid.
if (userSaysRevert()) { // reverted
ftf.postActionEvent(); // inform the editor
}
} else
try { // The text is valid,
ftf.commitEdit(); // so use it.
ftf.postActionEvent(); // stop editing
} catch (java.text.ParseException exc) {
}
}
});
}
示例6: AutoSwivelPanel
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
public AutoSwivelPanel()
{
maxSwivelField = new JFormattedTextField(NumberFormat.getNumberInstance());
minSwivelField = new JFormattedTextField(NumberFormat.getNumberInstance());
freedomOfTheGaussianMeanField = new JFormattedTextField(NumberFormat.getNumberInstance());
maxSwivelField.setValue(maxSwivel);
minSwivelField.setValue(minSwivel);
freedomOfTheGaussianMeanField.setValue(freedomOfTheGaussianMean);
panel.add(setupSwivelParam("min swivel", minSwivelField));
panel.add(setupSwivelParam("max swivel", maxSwivelField));
panel.add(setupSwivelParam("freedom of the Gaussian mean", freedomOfTheGaussianMeanField));
panel.add(swivelLabel);
}
示例7: SimulationSpeedControlPanel
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
public SimulationSpeedControlPanel( Font titleFont, Font controlFont, OTClock clock ) {
super();
_clock = clock;
_clock.addConstantDtClockListener( new ConstantDtClockAdapter() {
public void dtChanged( ConstantDtClockEvent event ) {
//XXX handle dt changes that are performed by someone else
};
});
// Title
JLabel titleLabel = new JLabel( OTResources.getString( "label.simulationSpeed" ) );
titleLabel.setFont( titleFont );
// Slider
_slider = new SimulationSpeedSlider( clock.getSlowRange(), clock.getFastRange(), clock.getDt() );
_slider.addChangeListener( new ChangeListener() {
public void stateChanged( ChangeEvent e ) {
setSimulationSpeed( _slider.getValue() );
}
});
PhetPCanvas canvas = new PhetPCanvas();
canvas.setBackground( getBackground() );
canvas.setBorder( null );
canvas.getLayer().addChild( _slider );
int margin = 2;
int xOffset = (int) -_slider.getFullBounds().getX() + margin;
int yOffset = (int) -_slider.getFullBounds().getY() + margin;
_slider.setOffset( xOffset, yOffset );
int w = (int) _slider.getFullBounds().getWidth() + ( 2 * margin );
int h = (int) _slider.getFullBounds().getHeight() + ( 2 * margin );
canvas.setPreferredSize( new Dimension( w, h ) );
// Textfield
_textField = new JFormattedTextField( VALUE_FORMAT );
_textField.setFont( controlFont );
_textField.setValue( new Double( _slider.getValue() ) );
_textField.setHorizontalAlignment( JTextField.RIGHT );
_textField.setColumns( VALUE_COLUMNS );
TextFieldListener textFieldListener = new TextFieldListener();
_textField.addActionListener( textFieldListener );
_textField.addFocusListener( textFieldListener );
// Units
JLabel unitsLabel = new JLabel( OTResources.getString( "units.time" ) );
unitsLabel.setFont( controlFont );
EasyGridBagLayout layout = new EasyGridBagLayout( this );
this.setLayout( layout );
layout.setAnchor( GridBagConstraints.WEST );
layout.setFill( GridBagConstraints.HORIZONTAL );
layout.setInsets( OTConstants.SUB_PANEL_INSETS );
int row = 0;
int column = 0;
layout.addComponent( titleLabel, row, column++ );
layout.addComponent( _textField, row, column++ );
layout.addComponent( unitsLabel, row, column++ );
row++;
column = 0;
layout.addComponent( canvas, row, column, 3, 1 );
setSimulationSpeed( clock.getDt() );
}
示例8: 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 );
}
示例9: getTableCellEditorComponent
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
JFormattedTextField ftf = (JFormattedTextField) super.getTableCellEditorComponent(table, value, isSelected, row, column);
ftf.setValue(value);
return ftf;
}
示例10: getTableCellEditorComponent
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
JFormattedTextField ftf = (JFormattedTextField) super.getTableCellEditorComponent(table, value, isSelected, row, column);
ftf.setValue(value);
return ftf;
}
示例11: IntegerCellEditor
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
/**
* Constructor.
* @param min the minimum of valid values.
* @param max the maximum of valid values.
*/
public IntegerCellEditor(int min, int max) {
super(new JFormattedTextField());
textField = (JFormattedTextField) getComponent();
minimum = new Integer(min);
maximum = new Integer(max);
// Set up the editor for the integer cells.
integerFormat = NumberFormat.getIntegerInstance();
NumberFormatter intFormatter = new NumberFormatter(integerFormat);
intFormatter.setFormat(integerFormat);
intFormatter.setOverwriteMode(false);
intFormatter.setMinimum(minimum);
intFormatter.setMaximum(maximum);
textField.setFormatterFactory(new DefaultFormatterFactory(intFormatter));
textField.setValue(minimum);
textField.setHorizontalAlignment(JTextField.TRAILING);
textField.setFocusLostBehavior(JFormattedTextField.PERSIST);
// React when the user presses Enter while the editor is
// active. (Tab is handled as specified by
// JFormattedTextField's focusLostBehavior property.)
textField.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "check");
textField.getActionMap().put("check", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if (!textField.isEditValid()) { //The text is invalid.
Toolkit.getDefaultToolkit().beep();
textField.selectAll();
} else {
try { //The text is valid,
textField.commitEdit(); //so use it.
textField.postActionEvent(); //stop editing
} catch (java.text.ParseException ex) {
}
}
}
});
}
示例12: DoubleCellEditor
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
/**
* Constructor.
* @param min the minimum of valid values.
* @param max the maximum of valid values.
*/
public DoubleCellEditor(double min, double max) {
super(new JFormattedTextField());
textField = (JFormattedTextField) getComponent();
minimum = new Double(min);
maximum = new Double(max);
// Set up the editor for the double cells.
doubleFormat = NumberFormat.getNumberInstance();
NumberFormatter doubleFormatter = new NumberFormatter(doubleFormat);
doubleFormatter.setFormat(doubleFormat);
doubleFormatter.setOverwriteMode(false);
doubleFormatter.setMinimum(minimum);
doubleFormatter.setMaximum(maximum);
textField.setFormatterFactory(new DefaultFormatterFactory(doubleFormatter));
textField.setValue(minimum);
textField.setHorizontalAlignment(JTextField.TRAILING);
textField.setFocusLostBehavior(JFormattedTextField.PERSIST);
// React when the user presses Enter while the editor is
// active. (Tab is handled as specified by
// JFormattedTextField's focusLostBehavior property.)
textField.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "check");
textField.getActionMap().put("check", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if (!textField.isEditValid()) { //The text is invalid.
Toolkit.getDefaultToolkit().beep();
textField.selectAll();
} else {
try { //The text is valid,
textField.commitEdit(); //so use it.
textField.postActionEvent(); //stop editing
} catch (java.text.ParseException ex) {
}
}
}
});
}
示例13: SoftSphereSolidEOSCalculator
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
public SoftSphereSolidEOSCalculator() {
super(new BorderLayout());
double density = 1.1964;
double temperature = 1.0;
double[] quantity = getAllQuantity(FCC, n, temperature, density);
//Create the labels.
densityLabel = new JLabel(densityString);
temperatureLabel = new JLabel(temperatureString);
bALabel = new JLabel(bAString);
ZLabel = new JLabel(ZString);
bULabel = new JLabel(bUString);
//Create the text fields and set them up.
densityField = new JFormattedTextField(densityFormat);
densityField.setValue(new Double(density));
densityField.setColumns(10);
densityField.addPropertyChangeListener("value", this);
temperatureField = new JFormattedTextField(temperatureFormat);
temperatureField.setValue(new Double(temperature));
temperatureField.setColumns(10);
temperatureField.addPropertyChangeListener("value", this);
bAField = new JFormattedTextField(bAFormat);
bAField.setValue(new Double(quantity[0]));
bAField.setColumns(10);
bAField.setEditable(false);
// paymentField.setForeground(Color.red);
ZField = new JFormattedTextField(ZFormat);
ZField.setValue(new Double(quantity[1]));
ZField.setColumns(10);
ZField.setEditable(false);
bUField = new JFormattedTextField(bUFormat);
bUField.setValue(new Double(quantity[2]));
bUField.setColumns(10);
bUField.setEditable(false);
//Tell accessibility tools about label/textfield pairs.
densityLabel.setLabelFor(densityField);
temperatureLabel.setLabelFor(temperatureField);
bALabel.setLabelFor(bAField);
ZLabel.setLabelFor(ZField);
bULabel.setLabelFor(bUField);
//Lay out the labels in a panel.
JPanel labelPane = new JPanel(new GridLayout(0,1));
labelPane.add(densityLabel);
labelPane.add(temperatureLabel);
labelPane.add(bALabel);
labelPane.add(ZLabel);
labelPane.add(bULabel);
//Layout the text fields in a panel.
JPanel fieldPane = new JPanel(new GridLayout(0,1));
fieldPane.add(densityField);
fieldPane.add(temperatureField);
fieldPane.add(bAField);
fieldPane.add(ZField);
fieldPane.add(bUField);
//Put the panels in this panel, labels on left,
//text fields on right.
setBorder(BorderFactory.createEmptyBorder(40, 40, 40, 40));
add(labelPane, BorderLayout.CENTER);
add(fieldPane, BorderLayout.LINE_END);
// LayoutStyle layout = new
}
示例14: 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;
}
示例15: 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);
}