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


Java JTextComponent.setText方法代码示例

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


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

示例1: setFieldData

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private void setFieldData(String[] textLines) {
    clearFieldData();

    for (String line : textLines) {
        String[] values = line.split("::");

        if (values.length == 2) {
            GridItem gridItem = componentMap.get(values[0]);

            if (gridItem.isExportable && gridItem.component instanceof JTextComponent) {
                JTextComponent field = ((JTextComponent) gridItem.component);
                field.setText(values[1]);
                field.setCaretPosition(0);
            }
        }
    }
}
 
开发者ID:jgmeyerucsd,项目名称:PIQEDia,代码行数:18,代码来源:GetInput.java

示例2: setTextFieldValue

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private void setTextFieldValue(String value, String projectValue, JTextComponent field) {
        if (value != null) {
            field.setText(value);
            component.setToolTipText(null);
            inherited = false;
            label.setFont(label.getFont().deriveFont(Font.BOLD));
        } else if (projectValue != null) {
            field.setText(projectValue);
            field.setSelectionEnd(projectValue.length());
            field.setSelectionStart(0);
//            field.setBackground(INHERITED);
            label.setFont(label.getFont().deriveFont(Font.PLAIN));
            component.setToolTipText(MSG_Value_Inherited());
            inherited = true;
        } else {
            field.setText("");//NOI18N
            component.setToolTipText(null);
            inherited = false;
            label.setFont(label.getFont().deriveFont(Font.BOLD));
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:TextComponentUpdater.java

示例3: initInputVerifiers

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private void initInputVerifiers () {
    InputVerifier iv = new InputVerifier() {
        @Override
        public boolean verify (JComponent input) {
            if (input == panel.startRevisionTextField || input == panel.endRevisionTextField || input == panel.oneRevisionTextField) {
                JTextComponent comp = (JTextComponent) input;
                if (comp.getText().trim().isEmpty()) {
                    comp.setText(SVNRevision.HEAD.toString());
                }
            }
            return true;
        }
    };
    panel.startRevisionTextField.setInputVerifier(iv);
    panel.endRevisionTextField.setInputVerifier(iv);
    panel.oneRevisionTextField.setInputVerifier(iv);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:RevertModifications.java

示例4: setPlainText

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private void setPlainText(JTextComponent field, String value, boolean loading) {
    if (value == null) {
        if (loading) {
            field.setText(LBL_Loading());
        } else {
            field.setText(LBL_Undefined());
        }
    } else {
        field.setText(value);
        field.setCaretPosition(0);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:ProjectInfoPanel.java

示例5: replacePattern

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private static void replacePattern(String pattern, JTextComponent area, String replace, boolean select) {
    String props = area.getText();
    Matcher match = Pattern.compile(pattern, Pattern.DOTALL).matcher(props);
    if (match.matches()) {
        int begin = props.indexOf(TestChecker.PROP_SKIP_TEST);
        props = props.replace(TestChecker.PROP_SKIP_TEST + match.group(1), replace); //NOI18N
        area.setText(props);
        if (select) {
            area.setSelectionStart(begin);
            area.setSelectionEnd(begin + replace.length());
            area.requestFocusInWindow();
        }
    } else {
        String sep = "\n";//NOI18N
        if (props.endsWith("\n") || props.trim().length() == 0) {//NOI18N
            sep = "";//NOI18N
        }
        props = props + sep + replace; //NOI18N
        area.setText(props);
        if (select) {
            area.setSelectionStart(props.length() - replace.length());
            area.setSelectionEnd(props.length());
            area.requestFocusInWindow();
        }
    }

}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:ActionMappings.java

示例6: verify

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public boolean verify (JComponent input) {
    if (input instanceof JTextComponent) {
        JTextComponent comp = (JTextComponent) input;
        if (comp.getText().trim().isEmpty()) {
            comp.setText(SVNRevision.HEAD.toString());
        }
    }
    return true;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:RepositoryPaths.java

示例7: setItem

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void setItem(Object anObject) {
    
    JTextComponent editor = getEditor();
    
    if (anObject != null)  {
        String text = anObject.toString();
        editor.setText(text);

        oldValue = anObject;
    } 
    else {
        editor.setText("");
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:ReturnTypeUIHelper.java

示例8: PopupPanel

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public PopupPanel(JPopupMenu popup)
{
	this.popup = popup;
	this.mapping = new HashMap<Locale, JTextComponent>();

	setLayout(new MigLayout("wrap,fill", "[grow]r[]", "")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
	for( Locale locale : editableLocales )
	{
		String actionCommand = locale.toString();
		JTextComponent field = getTextComponent();

		JButton button = new JButton(locale.getDisplayName());
		button.setActionCommand(actionCommand);
		button.addActionListener(this);

		field.setText(textMap.get(locale));
		mapping.put(locale, field);

		add(prepareTextComponent(field), "growx, sizegroup f, hmax 100px"); //$NON-NLS-1$
		add(button, "sizegroup b"); //$NON-NLS-1$
	}

	closeButton = new JLinkButton(CurrentLocale.get("prompts.close")); //$NON-NLS-1$
	closeButton.addActionListener(this);
	closeButton.setActionCommand(""); //$NON-NLS-1$
	closeButton.setIcon(new ArrowIcon(SwingConstants.NORTH));
	closeButton.setHorizontalTextPosition(SwingConstants.LEFT);
	add(closeButton, "span 2, align right, shrink"); //$NON-NLS-1$

	setBorder(BorderFactory.createLineBorder(Color.BLACK));

	final int width = Math.max(400, I18nTextField.this.getSize().width);
	setPreferredSize(new Dimension(width, getPreferredSize().height));

	popup.addPopupMenuListener(this);
}
 
开发者ID:equella,项目名称:Equella,代码行数:37,代码来源:I18nTextField.java

示例9: setText

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 * Set the <code>text</code> for the <code>textComp</code> and set its
 * caret position to the end of the text.
 */
public static void setText(JTextComponent textComp, String text) {
    textComp.setText(text);
    textComp.setCaretPosition(text == null ? 0 : text.length());
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:ApisupportAntUIUtils.java

示例10: setEditedComponent

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
void setEditedComponent(Component comp, String text) {
    if (!comp.isShowing() || comp.getParent() == null)
        throw new IllegalArgumentException();

    editedComp = comp;
    editedText = text;
    if (inPlaceField != null) {
        remove(inPlaceField);
        inPlaceField = null;
    }

    if (comp instanceof JLabel || comp instanceof AbstractButton || comp instanceof JTabbedPane) {
        layerEditing = true;
        superContainer = null;
        createInPlaceField();
    }
    else if (comp instanceof JTextField || comp instanceof JTextArea) {
        layerEditing = false;
        superContainer = comp.getParent();

        Container cont = superContainer;
        do {
            if (cont.getParent() instanceof JLayeredPane) {
                superContainer = cont;
                break;
            }
            else cont = cont.getParent();
        }
        while (cont != null);

        editingTextComp = (JTextComponent)editedComp;
        oldText = editingTextComp.getText();
        editingTextComp.setText(editedText);

        // enable focus on component in component layer
        editingTextComp.setFocusable(true);
        if (!editingTextComp.isEnabled()) {
            editingTextComp.setEnabled(true);
            enabled = true;
        }
        if (!editingTextComp.isEditable()) {
            editingTextComp.setEditable(true);
            madeEditable = true;
        }
    }
    else throw new IllegalArgumentException();

    if (editingTextComp != null) {
        FormUtils.setupTextUndoRedo(editingTextComp);
    }

    attachListeners();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:54,代码来源:InPlaceEditLayer.java

示例11: testCustomEditor

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void testCustomEditor() throws Exception {
    if (!canRun) return;
    
    requestFocus(stringRen);
    Runnable run = new Runnable() {
        public void run() {
            try {
                doCtrlPressKey(stringRen, KeyEvent.VK_SPACE);
            } catch (Exception e) {}
        }
    };
    new Thread(run).start();
    
    Thread.currentThread().sleep(1000);
    
    sleep();
    Component owner =
            KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
    
    assertNotNull("After invoking custom editor, focus owner should not be null", owner);
    
    assertTrue("Control press should invoke custom editor", ((JComponent) owner).getTopLevelAncestor() !=
            stringRen.getTopLevelAncestor());
    
    assertTrue("String custom editor should be a JTextComponent", owner instanceof JTextComponent);
    
    final JTextComponent jtc = (JTextComponent) owner;
    
    jtc.setText("Wuggle buggle");
    
    sleep();
    sleep();
    
    doCtrlPressKey(owner, KeyEvent.VK_TAB);
    
    sleep();
    sleep();
    
    Component okbutton =
            KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
    
    assertTrue("Button after editor in string renderer should be ok button", okbutton instanceof JButton);
    
    ((JButton) okbutton).doClick();
    sleep();
    sleep();
    sleep();
    
    assertEquals("After clicking ok on custom editor, property should be updated", "Wuggle buggle", stringRen.getProperty().getValue());
    sleep();
    assertEquals("After clicking ok button, inline editor should have the custom editor value", stringRen.getProperty().getValue(), stringRen.getEnteredValue());
    
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:54,代码来源:EditableDisplayerTest.java

示例12: setText

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private void setText (JTextComponent comp, String text) {
    comp.setText(text);
    comp.setCaretPosition(comp.getText().length());
    comp.moveCaretPosition(0);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:6,代码来源:ManageTags.java

示例13: setComboText

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private void setComboText (String item, int start, int end) {
    JTextComponent txt = (JTextComponent)panel.urlComboBox.getEditor().getEditorComponent();
    txt.setText(item);
    txt.setCaretPosition(end);
    txt.moveCaretPosition(start);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:RemoteRepository.java

示例14: DefaultPropertyValueCellEditor

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public DefaultPropertyValueCellEditor(final ParameterTypeStringCategory type) {
	super(new JComboBox(type.getValues()));

	if (type.isEditable()) {
		AutoCompleteComboBoxAddition autoCompleteCBA = new AutoCompleteComboBoxAddition((JComboBox) editorComponent);
		autoCompleteCBA.setCaseSensitive(false);
	}

	final JTextComponent textField = (JTextComponent) ((JComboBox) editorComponent).getEditor().getEditorComponent();

	useEditorAsRenderer = true;
	((JComboBox) editorComponent).removeItemListener(this.delegate);
	((JComboBox) editorComponent).setEditable(type.isEditable());
	this.delegate = new EditorDelegate() {

		private static final long serialVersionUID = -5592150438626222295L;

		@Override
		public void setValue(Object x) {
			if (x == null) {
				super.setValue(null);
				((JComboBox) editorComponent).setSelectedItem(null);
			} else {
				String value = x.toString();
				super.setValue(value);
				((JComboBox) editorComponent).setSelectedItem(value);
				if (value != null) {
					textField.setText(value.toString());
				} else {
					textField.setText("");
				}
			}
		}

		@Override
		public Object getCellEditorValue() {
			if (type.isEditable()) {
				String selected = textField.getText();
				if (selected != null && selected.trim().length() == 0) {
					selected = null;
				}
				return selected;
			} else {
				return ((JComboBox) editorComponent).getSelectedItem();
			}
		}
	};
	editorComponent.setToolTipText(type.getDescription());
	((JComboBox) editorComponent).addItemListener(delegate);
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:51,代码来源:DefaultPropertyValueCellEditor.java

示例15: updateFieldsFromState

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private void updateFieldsFromState() {
  isUpdating = true;
  properties.clear();

  final SequenceEncoder.Decoder defDecoder =
    new SequenceEncoder.Decoder(m_definition, DEF_DELIMITOR);
  final SequenceEncoder.Decoder stateDecoder =
    new SequenceEncoder.Decoder(state, STATE_DELIMITOR);

  for (int iField = 0; defDecoder.hasMoreTokens(); ++iField) {
    String name = defDecoder.nextToken();
    if (name.length() == 0) {
      continue;
    }

    final int type = name.charAt(0) - '0';
    name = name.substring(1);
    String value = stateDecoder.nextToken("");
    switch (type) {
    case TICKS:
    case TICKS_VAL:
    case TICKS_MAX:
    case TICKS_VALMAX:
      final int index = value.indexOf('/');
      properties.put(name, index > 0 ? value.substring(0, index) : value);
      break;
    default:
      properties.put(name, value);
    }

    value = value.replace(LINE_DELIMINATOR, '\n');

    if (frame != null) {
      final Object field = m_fields.get(iField);
      if (field instanceof JTextComponent) {
        final JTextComponent tf = (JTextComponent) field;
        final int pos = Math.min(tf.getCaretPosition(), value.length());
        tf.setText(value);
        tf.setCaretPosition(pos);
      }
      else if (field instanceof TickPanel) {
        ((TickPanel) field).updateValue(value);
      }
    }
  }

  if (applyButton != null) {
    applyButton.setEnabled(false);
  }

  isUpdating = false;
}
 
开发者ID:ajmath,项目名称:VASSAL-src,代码行数:53,代码来源:PropertySheet.java


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