當前位置: 首頁>>代碼示例>>Java>>正文


Java JFormattedTextField.setText方法代碼示例

本文整理匯總了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);
}
 
開發者ID:felixreimann,項目名稱:jreliability,代碼行數:27,代碼來源:MeasuresPanel.java

示例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);
      }
    }
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:29,代碼來源:MaskFormatter.java

示例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);
  }
 
開發者ID:gurkenlabs,項目名稱:litiengine,代碼行數:31,代碼來源:GridEditPanel.java

示例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;
            }
        }
    }
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:33,代碼來源:DefaultFormatter.java

示例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));
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:64,代碼來源:CellTypeTextFieldDefaultImpl.java

示例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());
}
 
開發者ID:leolewis,項目名稱:openvisualtraceroute,代碼行數:62,代碼來源:ControlPanel.java


注:本文中的javax.swing.JFormattedTextField.setText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。