Java Code Examples for javax.swing.text.JTextComponent#setText()
The following examples show how to use
javax.swing.text.JTextComponent#setText() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UndeployCommandDialog.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
public void actionPerformed(ActionEvent e) { StringBuilder builder = new StringBuilder("undeploy "); String name = deploymentChooser.getSelectedDeployment(); builder.append(name); if (keepContent.isSelected()) builder.append(" --keep-content"); if (!cliGuiCtx.isStandalone()) { addDomainParams(builder); } JTextComponent cmdText = cliGuiCtx.getCommandLine().getCmdText(); cmdText.setText(builder.toString()); dispose(); cmdText.requestFocus(); }
Example 2
Source File: StringToTextFieldAdapterService.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override public void fromPropertyToSwing( JComponent component, Property<?> property ) { String value; if( property == null ) { value = ""; } else { value = (String) property.get(); } if( component instanceof JTextComponent ) { JTextComponent textComponent = (JTextComponent) component; textComponent.setText( value ); } else { JLabel labelComponent = (JLabel) component; labelComponent.setText( value ); } }
Example 3
Source File: OperationDialog.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
public void actionPerformed(ActionEvent ae) { String addressPath = OperationDialog.this.node.addressPath(); if (OperationDialog.this.opName.equals("add")) { UserObject usrObj = (UserObject)OperationDialog.this.node.getUserObject(); ManagementModelNode parent = (ManagementModelNode)OperationDialog.this.node.getParent(); RequestProp resourceProp = OperationDialog.this.props.first(); String value = resourceProp.getValueAsString(); value = ManagementModelNode.escapeAddressElement(value); addressPath = parent.addressPath() + usrObj.getName() + "=" + value + "/"; OperationDialog.this.props.remove(resourceProp); } StringBuilder command = new StringBuilder(); command.append(addressPath); command.append(":"); command.append(OperationDialog.this.opName); addRequestProps(command, OperationDialog.this.props); JTextComponent cmdText = cliGuiCtx.getCommandLine().getCmdText(); cmdText.setText(command.toString()); OperationDialog.this.dispose(); cmdText.requestFocus(); }
Example 4
Source File: OperationMenu.java From wildfly-core with GNU Lesser General Public License v2.1 | 6 votes |
public void actionPerformed(ActionEvent ae) { JTextComponent cmdText = cliGuiCtx.getCommandLine().getCmdText(); ModelNode requestProperties = opDescription.get("result", "request-properties"); if (isNoArgOperation(requestProperties)) { cmdText.setText(addressPath + ":" + opName); cmdText.requestFocus(); return; } if (node.isLeaf() && opName.equals("undefine-attribute")) { UserObject usrObj = (UserObject)node.getUserObject(); cmdText.setText(addressPath + ":" + opName + "(name=" + usrObj.getName() + ")"); cmdText.requestFocus(); return; } OperationDialog dialog = new OperationDialog(cliGuiCtx, node, opName, strDescription, requestProperties); dialog.setLocationRelativeTo(cliGuiCtx.getMainWindow()); dialog.setVisible(true); }
Example 5
Source File: SwingUtil.java From jlibs with Apache License 2.0 | 5 votes |
/** * sets text of textComp without moving its caret. * * @param textComp text component whose text needs to be set * @param text text to be set. null will be treated as empty string */ public static void setText(JTextComponent textComp, String text){ if(text==null) text = ""; if(textComp.getCaret() instanceof DefaultCaret){ DefaultCaret caret = (DefaultCaret)textComp.getCaret(); int updatePolicy = caret.getUpdatePolicy(); caret.setUpdatePolicy(DefaultCaret.NEVER_UPDATE); try{ textComp.setText(text); }finally{ caret.setUpdatePolicy(updatePolicy); } }else{ int mark = textComp.getCaret().getMark(); int dot = textComp.getCaretPosition(); try{ textComp.setText(text); }finally{ int len = textComp.getDocument().getLength(); if(mark>len) mark = len; if(dot>len) dot = len; textComp.setCaretPosition(mark); if(dot!=mark) textComp.moveCaretPosition(dot); } } }
Example 6
Source File: FileUtils.java From weblaf with GNU General Public License v3.0 | 5 votes |
/** * Sets file name as text and selects its name part in any text component. * * @param editor text editor to process * @param file file to process */ public static void displayFileName ( @NotNull final JTextComponent editor, @NotNull final File file ) { final String name = file.getName (); editor.setText ( name ); editor.setSelectionStart ( 0 ); editor.setSelectionEnd ( file.isDirectory () ? name.length () : FileUtils.getFileNamePart ( name ).length () ); }
Example 7
Source File: ProjectInfoPanel.java From netbeans with Apache License 2.0 | 5 votes |
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); } }
Example 8
Source File: ClearTextAction.java From consulo with Apache License 2.0 | 5 votes |
public void actionPerformed(AnActionEvent e) { final Component component = e.getData(PlatformDataKeys.CONTEXT_COMPONENT); if (component instanceof JTextComponent) { final JTextComponent textComponent = (JTextComponent)component; textComponent.setText(""); } }
Example 9
Source File: ReturnTypeUIHelper.java From netbeans with Apache License 2.0 | 5 votes |
public void setItem(Object anObject) { JTextComponent editor = getEditor(); if (anObject != null) { String text = anObject.toString(); editor.setText(text); oldValue = anObject; } else { editor.setText(""); } }
Example 10
Source File: ConnectionParameterTextField.java From rapidminer-studio with GNU Affero General Public License v3.0 | 5 votes |
private JTextComponent createEditComponent() { JTextComponent textComponent = parameter.isEncrypted() ? getEncryptedTextComponent() : getTextComponent(); textComponent.setText(parameter.getValue()); if (parameter.isEditable()) { textComponent.getDocument().addDocumentListener(new TextChangedDocumentListener(parameter.valueProperty())); SwingTools.setPrompt(ConnectionI18N.getParameterPrompt(type, parameter.getGroupName(), parameter.getName(), null), textComponent); } return textComponent; }
Example 11
Source File: CopyHandler.java From jeveassets with GNU General Public License v2.0 | 5 votes |
public static void cut(JTextComponent jText) { String s = jText.getSelectedText(); if (s == null) { return; } if (s.length() == 0) { return; } String text = jText.getText(); String before = text.substring(0, jText.getSelectionStart()); String after = text.substring(jText.getSelectionEnd(), text.length()); jText.setText(before + after); CopyHandler.toClipboard(s); }
Example 12
Source File: DeployCommandDialog.java From wildfly-core with GNU Lesser General Public License v2.1 | 5 votes |
public void actionPerformed(ActionEvent e) { StringBuilder builder = new StringBuilder("deploy"); String path = pathField.getText(); if (!path.trim().isEmpty()) { builder.append(" ").append(path); } else { JOptionPane.showMessageDialog(this, "A file must be selected.", "Empty File Path", JOptionPane.ERROR_MESSAGE); return; } String name = nameField.getText(); if (!name.trim().isEmpty()) builder.append(" --name=").append(name); String runtimeName = runtimeNameField.getText(); if (!runtimeName.trim().isEmpty()) builder.append(" --runtime-name=").append(runtimeName); if (forceCheckBox.isSelected()) builder.append(" --force"); if (disabledCheckBox.isSelected() && disabledCheckBox.isEnabled()) builder.append(" --disabled"); if (!cliGuiCtx.isStandalone()) { if (allServerGroups.isSelected() && allServerGroups.isEnabled()) { builder.append(" --all-server-groups"); } else if (serverGroupChooser.isEnabled()) { builder.append(serverGroupChooser.getCmdLineArg()); } } JTextComponent cmdText = cliGuiCtx.getCommandLine().getCmdText(); cmdText.setText(builder.toString()); dispose(); cmdText.requestFocus(); }
Example 13
Source File: MainPanel.java From java-swing-tips with MIT License | 5 votes |
@Override public void focusLost(FocusEvent e) { JTextComponent tf = (JTextComponent) e.getComponent(); if ("".equals(tf.getText().trim())) { tf.setForeground(INACTIVE); tf.setText(hintMessage); } }
Example 14
Source File: AnnotationCellRenderer.java From mae-annotation with GNU General Public License v3.0 | 5 votes |
@Override public JTextComponent getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) { Component c = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, col); JTextComponent renderer; if (((TagTableModel) table.getModel()).isTextColumn(col)) { renderer = new JTextPane(); int fontSize = c.getFont().getSize(); ((JTextPane) renderer).setContentType("text/plain; charset=UTF-8"); ((JTextPane) renderer).setStyledDocument( FontHandler.stringToSimpleStyledDocument( (String) value, "dialog", fontSize, getCellForeground(isSelected))); } else { renderer = new JTextArea((String) value); renderer.setFont(c.getFont()); } if (col == TablePanelController.SRC_COL) { renderer.setText(FileHandler.getFileBaseName(getText())); } renderer.setMargin(new Insets(0, 2, 0, 2)); renderer.setOpaque(true); renderer.setForeground(getCellForeground(isSelected)); renderer.setToolTipText(value == null ? " " : (String) value); renderer.setBackground(c.getBackground()); renderer.setBorder(hasFocus ? UIManager.getBorder("Table.focusCellHighlightBorder") : BorderFactory.createEmptyBorder(1, 1, 1, 1)); return renderer; }
Example 15
Source File: TextHelpers.java From binnavi with Apache License 2.0 | 4 votes |
public static void insert(final JTextComponent component, final int position, final String string) { final String old = component.getText(); component.setText(old.substring(0, position) + string + old.substring(position)); }
Example 16
Source File: RemoteRepository.java From netbeans with Apache License 2.0 | 4 votes |
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); }
Example 17
Source File: ManageTags.java From netbeans with Apache License 2.0 | 4 votes |
private void setText (JTextComponent comp, String text) { comp.setText(text); comp.setCaretPosition(comp.getText().length()); comp.moveCaretPosition(0); }
Example 18
Source File: ApisupportAntUIUtils.java From netbeans with Apache License 2.0 | 4 votes |
/** * 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()); }
Example 19
Source File: InPlaceEditLayer.java From netbeans with Apache License 2.0 | 4 votes |
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(); }
Example 20
Source File: TextFieldsPanel.java From radiance with BSD 3-Clause "New" or "Revised" License | 4 votes |
@PerformanceScenarioParticipant public PerformanceScenario getSetTextComponentTextPerformanceScenario() { return new BasePerformanceScenario<JTextComponent>(TextFieldsPanel.this, JTextComponent.class, false) { int[] perms; @Override public String getName() { return "Changing text fields text"; } @Override public void setup() { super.setup(); this.perms = LightbeamUtils.getPermutation(LightbeamUtils.dictionary.length, getIterationCount() * this.controls.size() * 2); } @Override public int getIterationCount() { return 10; } ; @Override public void runSingleIteration(int iterationNumber) { int count = 0; for (JTextComponent field : this.controls) { int index = this.controls.size() * iterationNumber + count; if (field instanceof JFormattedTextField) { int value = 100 + this.perms[index] * 10; field.setText(value + "0.000"); } else { field.setText(LightbeamUtils.dictionary[this.perms[index]] + " " + LightbeamUtils.dictionary[this.perms[index + 1]]); } count++; } paintImmediately(new Rectangle(0, 0, getWidth(), getHeight())); } ; }; }