本文整理汇总了Java中javax.swing.JFormattedTextField.setText方法的典型用法代码示例。如果您正苦于以下问题:Java JFormattedTextField.setText方法的具体用法?Java JFormattedTextField.setText怎么用?Java JFormattedTextField.setText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JFormattedTextField
的用法示例。
在下文中一共展示了JFormattedTextField.setText方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createMtPanel
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
/**
* Creates the {@link JPanel} showing the mission time.
*
* @param maxwidth
* the dimension of the longest label
* @return the JPanel showing the mission time
*/
private JPanel createMtPanel(Dimension maxwidth) {
Double mtVal = inverse.evaluate(reliabilityFunction, standardMT);
JLabel pmtLabel = new JLabel("P[MT] =");
pmtLabel.setMinimumSize(maxwidth);
JLabel mtLabel = new JLabel("MT:");
mtLabel.setMinimumSize(maxwidth);
mtProbability = new JFormattedTextField(mtFieldFormat);
mtProbability.addActionListener(MeasurePanel.this);
mtProbability.setPreferredSize(new Dimension(70, 15));
mtProbability.setHorizontalAlignment(SwingConstants.RIGHT);
mtProbability.setText(standardMT.toString());
mt = new JLabel(mtVal.toString());
return createSubPanel("Mission-Time", pmtLabel, mtProbability, mtLabel, mt);
}
示例2: install
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
/**
* Installs this MaskFormatter on the JFormattedTextField.
* Invokes valueToString to convert the current value from the
* JFormattedTextField to a String, then installs the Actions from
* getActions, the DocumentFilter from getDocumentFilter, and the
* NavigationFilter from getNavigationFilter.
*
* If valueToString throws a ParseException, this method sets the text
* to an empty String and marks the JFormattedTextField as invalid.
*/
public void install (JFormattedTextField ftf)
{
super.install(ftf);
if (ftf != null)
{
try
{
valueToString(ftf.getValue());
}
catch (ParseException pe)
{
// Set the text to an empty String and mark the JFormattedTextField
// as invalid.
ftf.setText("");
setEditValid(false);
}
}
}
示例3: 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);
}
示例4: checkValidInput
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
/**
* Checks if the value in the input field is valid. If the
* property allowsInvalid is set to <code>false</code>, then
* the string in the input field is not allowed to be entered.
*/
private void checkValidInput()
{
JFormattedTextField ftf = getFormattedTextField();
try
{
Object newval = stringToValue(ftf.getText());
}
catch (ParseException ex)
{
if (!allowsInvalid)
{
// roll back the input if invalid edits are not allowed
try
{
ftf.setText(valueToString(ftf.getValue()));
}
catch (ParseException pe)
{
// if that happens, something serious must be wrong
AssertionError ae;
ae = new AssertionError("values must be parseable");
ae.initCause(pe);
throw ae;
}
}
}
}
示例5: CellTypeTextFieldDefaultImpl
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
/**
* Creates a {@link JFormattedTextField} for the specified cell. If a formatter is given, will
* apply it to the field. Does not validate the model, so make sure this call works!
*
* @param model
* @param rowIndex
* @param columnIndex
* @param cellClass
* @param formatter
* the formatter or <code>null</code> if none is required
* @param hideUnavailableContentAssist
* @return
*/
public CellTypeTextFieldDefaultImpl(final TablePanelModel model, final int rowIndex, final int columnIndex,
final Class<? extends CellType> cellClass, AbstractFormatter formatter, boolean hideUnavailableContentAssist) {
super();
final JFormattedTextField field = CellTypeImplHelper.createFormattedTextField(model, rowIndex, columnIndex);
setLayout(new BorderLayout());
add(field, BorderLayout.CENTER);
// otherwise 'null' would be restored
Object value = model.getValueAt(rowIndex, columnIndex);
String text = value != null ? String.valueOf(value) : "";
// specical handling when formatter is given
if (formatter != null) {
field.setFormatterFactory(new DefaultFormatterFactory(formatter));
}
field.setText(text);
// set syntax assist if available
String syntaxHelp = model.getSyntaxHelpAt(rowIndex, columnIndex);
if (syntaxHelp != null && !"".equals(syntaxHelp.trim())) {
PromptSupport.setForeground(Color.LIGHT_GRAY, field);
PromptSupport.setPrompt(syntaxHelp, field);
PromptSupport.setFontStyle(Font.ITALIC, field);
PromptSupport.setFocusBehavior(FocusBehavior.SHOW_PROMPT, field);
}
// see if content assist is possible for this field, if so add it
ImageIcon icon = SwingTools.createIcon("16/"
+ I18N.getMessageOrNull(I18N.getGUIBundle(), "gui.action.content_assist.icon"));
JButton contentAssistButton = new JButton();
contentAssistButton.setIcon(icon);
if (field.isEnabled() && model.isContentAssistPossibleForCell(rowIndex, columnIndex)) {
contentAssistButton.setToolTipText(I18N.getMessageOrNull(I18N.getGUIBundle(),
"gui.action.content_assist_enabled.tip"));
CellTypeImplHelper.addContentAssist(model, rowIndex, columnIndex, field, contentAssistButton, cellClass);
} else {
contentAssistButton.setToolTipText(I18N.getMessageOrNull(I18N.getGUIBundle(),
"gui.action.content_assist_disabled.tip"));
contentAssistButton.setEnabled(false);
}
if (contentAssistButton.isEnabled() || (!contentAssistButton.isEnabled() && !hideUnavailableContentAssist)) {
add(contentAssistButton, BorderLayout.EAST);
}
// set size so panels don't grow larger when they get the chance
setPreferredSize(new Dimension(300, 20));
setMinimumSize(new Dimension(100, 15));
setMaximumSize(new Dimension(1600, 30));
}
示例6: SnifferControl
import javax.swing.JFormattedTextField; //导入方法依赖的package包/类
public SnifferControl() {
super();
setLayout(new FlowLayout(FlowLayout.LEFT, 2, 0));
_hostIpTextField = new JTextField(17);
_hostIpTextField.setText(Resources.getLabel("sniffer.host.tooltip"));
final FirstInputListener listener = new FirstInputListener(_hostIpTextField);
_hostIpTextField.addMouseListener(listener);
_hostIpTextField.addKeyListener(listener);
_hostIpTextField.setToolTipText(Resources.getLabel("sniffer.host.tooltip"));
add(_hostIpTextField);
final JLabel protocolLabel = new JLabel(Resources.getLabel("protocol.label"));
protocolLabel.setToolTipText(Resources.getLabel("protocol.desc"));
add(protocolLabel);
for (final Protocol type : Protocol.values()) {
if (type == Protocol.OTHER) {
continue;
}
final JCheckBox check = new JCheckBox(type.name(), type == Protocol.TCP);
_packets.put(type, check);
add(check);
}
final JLabel portLabel = new JLabel(Resources.getLabel("port.label"));
portLabel.setToolTipText(Resources.getLabel("port.desc"));
_allPortCheck = new JCheckBox(Resources.getLabel("all.port.label"));
_allPortCheck.setToolTipText(Resources.getLabel("all.port.desc"));
_allPortCheck.setSelected(false);
add(_allPortCheck);
_portTF = new JFormattedTextField();
_portTF.setText("80,443");
_portTF.setColumns(15);
// _portTF.setMaximumSize(new Dimension(30, _portTF.getPreferredSize().height));
add(portLabel);
add(_portTF);
_portTF.setEnabled(true);
_allPortCheck.addChangeListener(e -> _portTF.setEnabled(!_allPortCheck.isSelected()));
_filterPacketLengthCheck = new JCheckBox(Resources.getLabel("filter.length"));
_filterPacketLengthCheck.setToolTipText(Resources.getLabel("filter.length.desc"));
_filterPacketLengthCheck.setSelected(false);
add(_filterPacketLengthCheck);
_filterLengthTF = new JFormattedTextField(new NumberFormatterFactory());
_filterLengthTF.setText("128");
_filterLengthTF.setColumns(5);
add(_filterLengthTF);
_filterPacketLengthCheck.addChangeListener(e -> _filterLengthTF.setEnabled(_filterPacketLengthCheck.isEnabled() && _filterPacketLengthCheck.isSelected()));
_capturePeriod = new JFormattedTextField(new NumberFormatterFactory());
_capturePeriod.setText("0");
_capturePeriod.setColumns(5);
add(new JLabel(Resources.getLabel("capture.period")));
add(_capturePeriod);
_captureButton = new JButton(GO_IMG);
_captureButton.setToolTipText(Resources.getLabel("capture.packet.start"));
add(_captureButton);
_captureButton.addActionListener(arg0 -> start());
}