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


Java JTextComponent.getText方法代码示例

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


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

示例1: getItem

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public Object getItem() {
    
    JTextComponent editor = getEditor();
    
    Object newValue = editor.getText();

    if (oldValue != null && !(oldValue instanceof String))  {
        // The original value is not a string. Should return the value in it's
        // original type.
        if (newValue.equals(oldValue.toString()))  {
            return oldValue;
        } else {
            // Must take the value from the editor and get the value and cast it to the new type.
            Class<?> cls = oldValue.getClass();
            try {
                Method method = cls.getMethod("valueOf", String.class); // NOI18N
                newValue = method.invoke(oldValue, new Object[] { editor.getText() });
            } catch (Exception ex) {
                // Fail silently and return the newValue (a String object)
                Logger.getLogger("ReturnTypeUIHelper").log(Level.FINE, "ignored excep[tion", ex);  //NOI18N
            }
        }
    }
    return newValue;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:26,代码来源:ReturnTypeUIHelper.java

示例2: setText

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private void setText(Locale locale, JTextComponent textField)
{
	final String text = textField.getText();
	final boolean isEmpty = text.length() == 0;

	String replaced = isEmpty ? textMap.remove(locale) : textMap.put(locale, text);
	if( replaced == null )
	{
		replaced = ""; //$NON-NLS-1$
	}

	if( !text.equals(replaced) )
	{
		changesDetected = true;
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:17,代码来源:I18nTextField.java

示例3: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent e) {

         JTextComponent tc = getTextComponent(e);
         String filename = null;

         // Get the name of the file to load. If there is a selection, use
         // that as the file name, otherwise, scan for a filename around
         // the caret.
         try {
            int selStart = tc.getSelectionStart();
            int selEnd = tc.getSelectionEnd();
            if (selStart != selEnd) {
               filename = tc.getText(selStart, selEnd - selStart);
            } else {
               filename = getFilenameAtCaret(tc);
            }
         } catch (BadLocationException ble) {
            ble.printStackTrace();
            UIManager.getLookAndFeel().provideErrorFeedback(tc);
            return;
         }

         menuFunctions.loadFile(new File(filename));

      }
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:26,代码来源:PTextEditor.java

示例4: mouseClicked

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void mouseClicked(MouseEvent e) {
    if (e.getModifiers() == InputEvent.BUTTON3_MASK) {
        if (!(e.getSource() instanceof JTextComponent)) {
            return;
        }

        textComponent = (JTextComponent) e.getSource();
        textComponent.requestFocus();

        boolean enabled = textComponent.isEnabled();
        boolean editable = textComponent.isEditable();
        boolean nonempty = !(textComponent.getText() == null || textComponent.getText().equals(""));
        boolean marked = textComponent.getSelectedText() != null;

        boolean pasteAvailable = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null).isDataFlavorSupported(DataFlavor.stringFlavor);

        undoAction.setEnabled(enabled && editable && (lastActionSelected == Actions.CUT || lastActionSelected == Actions.PASTE));
        cutAction.setEnabled(enabled && editable && marked);
        copyAction.setEnabled(enabled && marked);
        pasteAction.setEnabled(enabled && editable && pasteAvailable);
        selectAllAction.setEnabled(enabled && nonempty);

        int nx = e.getX();

        if (nx > 500) {
            nx = nx - popup.getSize().width;
        }

        popup.show(e.getComponent(), nx, e.getY() - popup.getSize().height);
    }
}
 
开发者ID:RipMeApp,项目名称:ripme,代码行数:33,代码来源:ContextMenuMouseListener.java

示例5: prepareEditor

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private void prepareEditor() {
    Component c = getEditor().getEditorComponent();

    if (c instanceof JTextComponent) {
        JTextComponent jtc = (JTextComponent) c;
        String s = jtc.getText();

        if ((s != null) && (s.length() > 0)) {
            jtc.setSelectionStart(0);
            jtc.setSelectionEnd(s.length());
        }

        if (tableUI) {
            jtc.setBackground(getBackground());
        } else {
            jtc.setBackground(PropUtils.getTextFieldBackground());
        }
        if( tableUI )
            jtc.requestFocus();
    }

    if (getLayout() != null) {
        getLayout().layoutContainer(this);
    }

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

示例6: getComponent

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
    protected JComponent getComponent() {
        JTextComponent text = getTextComponent();

        if (text == null) {
            return null;
        }
        if (Config.getDefault().isAsEditor()) {
            return getEditorComponent(text);
        }
        Document document = myEditor.getDocument();

        if (document == null) {
            return null;
        }
        int start;
        int end;

        if (Config.getDefault().isSelection()) {
            start = text.getSelectionStart();
            end = text.getSelectionEnd();
        }
        else {
            start = 0;
            end = document.getLength();
        }
        AttributedCharacterIterator[] iterators = getIterators(document, start, end);
//out();
//out("iterators: " + iterators);
//out();
        if (iterators != null) {
            return new ComponentDocument(iterators);
        }
        try {
            return new ComponentDocument(text.getText(start, end - start));
        }
        catch (BadLocationException e) {
            return null;
        }
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:41,代码来源:EditorProvider.java

示例7: 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

示例8: getTextLength

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private int getTextLength(JTextComponent c) {
	if (c == null) {
		return 0;
	}
	if (c.getText() == null) {
		return 0;
	}
	return c.getText().length();
}
 
开发者ID:transwarpio,项目名称:rapidminer,代码行数:10,代码来源:ClipboardActionsPopup.java

示例9: updateToolTipText

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 * Updates the text in the tool tip to have the current parameter
 * displayed in bold.  The "current parameter" is determined from the
 * current caret position.
 *
 * @return The "prefix" of text in the caret's parameter before the caret.
 */
private String updateToolTipText() {

	JTextComponent tc = ac.getTextComponent();
	int dot = tc.getSelectionStart();
	int mark = tc.getSelectionEnd();
	int index = -1;
	String paramPrefix = null;

	List<Highlight> paramHighlights = getParameterHighlights();
	for (int i=0; i<paramHighlights.size(); i++) {
		Highlight h = paramHighlights.get(i);
		// "+1" because of param hack - see OutlineHighlightPainter
		int start = h.getStartOffset()+1;
		if (dot>=start && dot<=h.getEndOffset()) {
			try {
				// All text selected => offer all suggestions, otherwise
				// use prefix before selection
				if (dot!=start || mark!=h.getEndOffset()) {
					paramPrefix = tc.getText(start, dot-start);
				}
			} catch (BadLocationException ble) {
				ble.printStackTrace();
			}
			index = i;
			break;
		}
	}

	updateToolTipText(index);
	return paramPrefix;

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:40,代码来源:ParameterizedCompletionContext.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: getText

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
String getText() {
    JTextComponent textC = getTextComponent();
    return textC != null ? textC.getText() : getSelectedItem().toString();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:5,代码来源:EditableHistoryCombo.java

示例12: 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


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