Demos and Usage of javax.swing.text.JTextComponent.setCaretPosition(int position)


   1: import javax.swing.JComponent;
   2: import javax.swing.text.JTextComponent;
   3: 
   4:         ...
   5:         if (isCompatible(component)) {
   6:             JTextComponent jtc = (JTextComponent)component;
   7:             String sData = data.toString();
   8:         ...
   9:             jtc.setText(sData);
  10:             jtc.setCaretPosition(0);
  11:         } else

View Full Code Here
   1:       String         str =_data.toString();
   2:       JTextComponent text=(JTextComponent)_component;
   3:       Document       doc =text.getDocument();
   4:         ...
   5: 
   6:           text.setCaretPosition(pos);
   7:           doc.insertString(pos,str,null);
   8:           r=true;
   9:           

View Full Code Here
   1: import java.io.IOException;
   2: import javax.swing.text.JTextComponent;
   3: import javax.swing.text.Document;
   4:         ...
   5:   public static PrintStream getPrintStreamOfTextComponent(
   6:       JTextComponent comp) {
   7:     OutputStream os = new TextComponentOutputStream(comp);
   8:         ...
   9:       extends OutputStream {
  10:     private final JTextComponent comp;
  11:     private final Document doc;
  12:         ...
  13:           if (comp.getCaretPosition() == length) {
  14:             comp.setCaretPosition(length + string.length());

View Full Code Here
   1: import javax.swing.KeyStroke;
   2: import javax.swing.text.JTextComponent;
   3: 
   4:         ...
   5: 
   6:     private JTextComponent  m_codeText;
   7:     private ICodeFormatter  m_formatter;
   8:         ...
   9:     
  10:     protected abstract JTextComponent createTextComponent();
  11:     
  12:         ...
  13:                 m_codeText.setDocument(formatted.getDocument());
  14:                 m_codeText.setCaretPosition(formatted.getCaretPosition());

View Full Code Here
   1: import javax.swing.JScrollPane;
   2: import javax.swing.text.JTextComponent;
   3: 
   4:         ...
   5:         private void addDocumentation(String documentation, JPanel cp) {
   6:             JTextComponent tc = ComponentFactories.textFactory().newHtmlDisplayer();
   7:             tc.setText(documentation);
   8:         ...
   9:             tc.setCaretPosition(0);
  10:             setFocusedComponent(tc);

View Full Code Here
   1: import javax.swing.text.Document;
   2: import javax.swing.text.JTextComponent;
   3: 
   4:         ...
   5: 
   6:     private JTextComponent      m_target;
   7:     private KeyBindingInstaller m_keyBindings;
   8:         ...
   9: 
  10:     public void install(JTextComponent text) {
  11:         if (text == null) {
  12:         ...
  13:             IInterval interval = token.getInterval(doc);
  14:             m_target.setCaretPosition(interval.startsAt() + interval.length());

View Full Code Here
   1: import javax.swing.text.StyledEditorKit;
   2: import javax.swing.text.JTextComponent;
   3: import javax.swing.JEditorPane;
   4:         ...
   5:     private JSpellDialog dlg;
   6:     private JTextComponent textComp;
   7:     private SpellDictionary mainDict;
   8:         ...
   9: 
  10:     private void setupDialog (JTextComponent textComp)
  11:     {
  12:         ...
  13:         textComp.requestFocus();
  14:         textComp.setCaretPosition(0);

View Full Code Here
   1: import javax.swing.JComboBox;
   2: import javax.swing.text.JTextComponent;
   3: 
   4:         ...
   5:     private void startEditing() {
   6:         JTextComponent textField = (JTextComponent) combo.getEditor().getEditorComponent();
   7: 
   8:         ...
   9:         if (i != -1)
  10:             textField.setCaretPosition(i + 2);
  11:         else

View Full Code Here
   1: {
   2:     public HistoryText(JTextComponent text, String name)
   3:     {
   4:         ...
   5:         {
   6:             text.setCaretPosition(getDocument().getLength());
   7:         }
   8:         ...
   9:         {
  10:             text.setCaretPosition(getDocument().getLength());
  11:         }
  12:         ...
  13: 
  14:     private JTextComponent text;

View Full Code Here
   1: {
   2:     public HistoryText(JTextComponent text, String name)
   3:     {
   4:         ...
   5:         {
   6:             text.setCaretPosition(getDocument().getLength());
   7:         }
   8:         ...
   9:         {
  10:             text.setCaretPosition(getDocument().getLength());
  11:         }
  12:         ...
  13: 
  14:     private JTextComponent text;

View Full Code Here
   1:     ComboBoxModel model;
   2:     JTextComponent editor;
   3:     boolean selecting=false;
   4:         ...
   5:         if (newEditor != null) {
   6:             editor = (JTextComponent) newEditor.getEditorComponent();
   7:             editor.addKeyListener(editorKeyListener);
   8:         ...
   9:     private void highlightCompletedText(int start) {
  10:         editor.setCaretPosition(getLength());
  11:         editor.moveCaretPosition(start);

View Full Code Here
   1: import javax.swing.text.Document;
   2: import javax.swing.text.JTextComponent;
   3: 
   4:         ...
   5:     
   6:     public static SearchResult findText(final JTextComponent textComponent, final String text, final int fromIndex, final Flags flags) {
   7:     }
   8:         ...
   9: 
  10:     public static SearchResult findNextText(final JTextComponent textComponent, final String text, final Flags flags) {
  11:         if (result1 == SearchResult.WRAP_AROUND) {
  12:         ...
  13:         if (foundAt != -1) {
  14:             textComponent.setCaretPosition(foundAt);

View Full Code Here
   1: import javax.swing.ListModel;
   2: import javax.swing.text.JTextComponent;
   3: 
   4:         ...
   5:             String text = getCaptionText();
   6:             JTextComponent tc = ComponentFactories.textFactory().newTextArea(text, 4, 40);
   7:             tc.setEditable(false);
   8:         ...
   9:             tc.setCaretPosition(0);
  10:             return ComponentFactories.scrollFactory().newScrollPane(tc);

View Full Code Here
   1: 
   2: import javax.swing.text.JTextComponent;
   3: 
   4:         ...
   5:         String value = HostedWebServiceConfiguration.getWebServiceUrl(op);
   6:         JTextComponent text = ComponentFactories.textFactory().newTextField(value, 40);
   7:         ...
   8:         text.setCaretPosition(0);
   9:         text.setEditable(false);

View Full Code Here
   1: import javax.swing.KeyStroke;
   2: import javax.swing.text.JTextComponent;
   3: 
   4:         ...
   5:     
   6:     private JTextComponent m_editor;
   7:     private boolean        m_editing;
   8:         ...
   9:     
  10:     public JTextComponent getTextEditor() {
  11:         return m_editor;
  12:         ...
  13:         m_editor.setVisible(true);
  14:         m_editor.setCaretPosition(txt.length());

View Full Code Here