本文整理汇总了Java中javax.swing.JFormattedTextField.setEditable方法的典型用法代码示例。如果您正苦于以下问题:Java JFormattedTextField.setEditable方法的具体用法?Java JFormattedTextField.setEditable怎么用?Java JFormattedTextField.setEditable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFormattedTextField
的用法示例。
在下文中一共展示了JFormattedTextField.setEditable方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: IntegerEditor
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
/**
* Construct a <code>JSpinner</code> editor that supports displaying and
* editing the value of a <code>SpinnerIntModel</code> with a
* <code>JFormattedTextField</code>. <code>This</code>
* <code>IntegerEditor</code> becomes both a <code>ChangeListener</code>
* on the spinner and a <code>PropertyChangeListener</code> on the new
* <code>JFormattedTextField</code>.
*
* @param spinner the spinner whose model <code>this</code> editor will
* monitor
* @param format the <code>NumberFormat</code> object that's used to
* display and parse the value of the text field.
* @exception IllegalArgumentException if the spinners model is not an
* instance of <code>SpinnerIntModel</code>
*
* @see #getTextField
* @see SpinnerIntModel
* @see java.text.DecimalFormat
*/
private IntegerEditor(JSpinner spinner, NumberFormat format) {
super(spinner);
if (!(spinner.getModel() instanceof SpinnerIntModel)) {
throw new IllegalArgumentException("model not a SpinnerIntModel");
}
format.setGroupingUsed(false);
format.setMaximumFractionDigits(0);
SpinnerIntModel model = (SpinnerIntModel) spinner.getModel();
NumberFormatter formatter = new IntegerEditorFormatter(model, format);
DefaultFormatterFactory factory = new DefaultFormatterFactory(formatter);
JFormattedTextField ftf = getTextField();
ftf.setEditable(true);
ftf.setFormatterFactory(factory);
ftf.setHorizontalAlignment(JTextField.RIGHT);
try {
String minString = formatter.valueToString(model.getMinimum());
String maxString = formatter.valueToString(model.getMaximum());
// Trying to approximate the width difference between "m" and "0" by multiplying with 0.7
ftf.setColumns((int) Math.round(0.7 * Math.max(maxString.length(), minString.length())));
} catch (ParseException e) {
// Nothing to do, the component width will simply be the default
}
}
示例2: HexaEditor
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
HexaEditor (JSpinner spinner)
{
super(spinner);
JFormattedTextField ftf = getTextField();
ftf.setEditable(true);
ftf.setFormatterFactory(new HexaFormatterFactory());
}
示例3: PgTimeSpinner
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
/** Create a new page time spinner */
public PgTimeSpinner() {
setModel(new PgTimeSpinnerModel(
PageTimeHelper.defaultPageOnInterval().seconds(),
PageTimeHelper.minPageOnInterval(), INC_ONTIME_SECS));
setToolTipText(I18N.get("dms.page.on.time.tooltip"));
// force the spinner to be editable
JFormattedTextField tf = ((JSpinner.DefaultEditor)
this.getEditor()).getTextField();
tf.setEditable(true);
}
示例4: 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
}