本文整理了Java中javax.swing.text.JTextComponent.setCaretPosition()
方法的一些代码示例,展示了JTextComponent.setCaretPosition()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JTextComponent.setCaretPosition()
方法的具体详情如下:
包路径:javax.swing.text.JTextComponent
类名称:JTextComponent
方法名:setCaretPosition
暂无
代码示例来源:origin: stackoverflow.com
+ "Blabla\nBlabla\nBlabla\nBlabla\nBlabla\nBlabla\n");
textArea.setSelectionColor(Color.RED);
frame.add(pane);
frame.setSize(300, 120);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
System.out.println("Y : " + y);
System.out.println("Y (pos2) : " + startIndex.y);
textArea.setCaretPosition(textArea.viewToModel(new Point(startIndex.x, y)));
pane.scrollRectToVisible(new Rectangle(startIndex.x, y));
代码示例来源:origin: stackoverflow.com
String newText = left + "v" + right;
tf.setText(newText);
tf.setCaretPosition(caretPosition+1);
tf.requestFocus();
JPanel p = (JPanel)f.getContentPane();
p.setLayout(new BorderLayout());
p.add(b, BorderLayout.EAST);
p.add(tf, BorderLayout.CENTER);
f.setSize(640, 400);
f.setVisible(true);
代码示例来源:origin: stackoverflow.com
inputCat.setCaretPosition(0);
listPane.add(comboBox);
listPane.add(Box.createHorizontalStrut(10));
listPane.add(inputCat);
listPane.add(Box.createHorizontalStrut(10));
listPane.add(spinner);
代码示例来源:origin: stackoverflow.com
StyleConstants.setForeground(aset, c);
int len = getText().length();
setCaretPosition(len); // place caret at the end (with no selection)
setCharacterAttributes(aset, false);
int len = getDocument().getLength(); // same value as
setCaretPosition(len); // place caret at the end (with no selection)
setCharacterAttributes(aset, false);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setContentPane(new JScrollPane(pane));
f.setSize(600, 400);
f.setVisible(true);
代码示例来源:origin: stackoverflow.com
SwingUtilities.invokeAndWait(() -> {
final JFrame jFrame = new JFrame();
jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jFrame.setLayout(new BorderLayout());
doc.remove(0, doc.getLength());
editorKit.insertHTML(doc, 0, "<a href=\"http://google.com\">link one</a> and <a href=\"http://bing.com\">link two</a>", 0, 0, null);
editor.setCaretPosition(0);
} catch (final Exception e) {
e.printStackTrace();
代码示例来源:origin: stackoverflow.com
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
topPanel.add(tPane);
appendToPane(tPane, "flow", Color.ORANGE);
getContentPane().add(topPanel);
setVisible(true);
tp.setCaretPosition(len);
tp.setCharacterAttributes(aset, false);
tp.replaceSelection(msg);
代码示例来源:origin: stackoverflow.com
System.out.println("length: "
+ jTextArea1.getText().length());
jTextArea1.setCaretPosition(0);
System.out.println("length: "
+ jTextArea2.getText().length());
jTextArea2.setCaretPosition(0);
jTextArea2.setText("This TextArea WILL");
frame.add(jTextArea1);
frame.add(jTextArea2);
frame.setSize(500, 500);
frame.setVisible(true);
代码示例来源:origin: stackoverflow.com
container.add(new JScrollPane(displayArea), BorderLayout.SOUTH );
displayArea.setCaretPosition(displayArea.getText().length());
代码示例来源:origin: stackoverflow.com
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
contentPane.add(scrollPane);
Highlighter highlighter = tarea.getHighlighter();
highlighter.removeHighlight(highlights.get(startIndex));
tarea.setCaretPosition(startIndex);
tarea.requestFocusInWindow();
highlights.remove(startIndex);
frame.add(remHighButton, BorderLayout.PAGE_START);
frame.add(contentPane, BorderLayout.CENTER);
frame.add(button, BorderLayout.PAGE_END);
frame.setVisible(true);
代码示例来源:origin: stackoverflow.com
JTextArea textArea = new JTextArea(text, 1, 30); // shows only one line
JScrollPane scrollPane = new JScrollPane( textArea );
frame.add(scrollPane);
frame.pack();
frame.setVisible(true);
textArea.setCaretPosition(text.length());
代码示例来源:origin: hneemann/Digital
private void init(Window parent, String str, boolean html) {
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
JTextComponent textComp;
if (html) {
textComp = new JEditorPane("text/html", str);
textComp.setCaretPosition(0);
textComp.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true);
textComp.setPreferredSize(Screen.getInstance().scale(new Dimension(600, 800)));
} else {
textComp = new JTextArea(str);
textComp.setFont(new JLabel().getFont());
}
textComp.setEditable(false);
textComp.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
getContentPane().add(new JScrollPane(textComp));
pack();
setLocationRelativeTo(parent);
}
}
代码示例来源:origin: stackoverflow.com
buttonPanel.add(saveButton);
add(buttonPanel, BorderLayout.PAGE_START);
add(logScrollPane, BorderLayout.CENTER);
content.setCaretPosition(content.getDocument().getLength());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new MyFileChooser());
frame.setVisible(true);
代码示例来源:origin: stackoverflow.com
scrollPane=new JScrollPane(textArea);
tabbedPane2=new JTabbedPane();
this.add(tabbedPane2);
enableDragAndDrop();
DropTarget target=new DropTarget(newTabTextArea,this);
newTabTextArea.read(new FileReader(file),null);
newTabTextArea.setCaretPosition(0);
tabbedPane2.add(newTabTextArea);
int tabIndex=tabbedPane2.indexOfComponent(newTabTextArea);
new DragAndDropFile().setVisible(true);
代码示例来源:origin: stackoverflow.com
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ta = new JTextArea();
DefaultCaret caret = (DefaultCaret) ta.getCaret();
caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
frame.add(new JScrollPane(ta));
frame.setSize(400, 200);
frame.setVisible(true);
new UpdateText().execute();
ta.setCaretPosition(ta.getLineStartOffset(ta.getLineCount() - 1));
} catch (BadLocationException e) {
代码示例来源:origin: stackoverflow.com
TableColumn tc = tcm.getColumn(1);
tc.setCellEditor(new SpinnerEditor());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(table);
frame.pack();
frame.setVisible(true);
public void run() {
if ( valueSet ) {
textField.setCaretPosition(1);
代码示例来源:origin: stackoverflow.com
import javax.swing.*;
import java.awt.*;
/** @see http://stackoverflow.com/questions/6536178 */
public class JTextAreaPasteTest {
public static void main(String argv[]) {
EventQueue.invokeLater(new Runnable() {
public void run() {
display();
}
});
}
private static void display() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
String testStr = "Paste text here.";
JTextArea wrapArea = new JTextArea(testStr, 20, 40);
wrapArea.setLineWrap(true);
wrapArea.setWrapStyleWord(true);
wrapArea.setCaretPosition(testStr.length());
frame.add(new JScrollPane(wrapArea));
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
代码示例来源:origin: stackoverflow.com
text = new JTextField("Test Test Test Test Test Test Test Test", JLabel.RIGHT);
int textLength = text.getText().length() - 2;
text.setCaretPosition(textLength);
setLayout(new BorderLayout());
add(BorderLayout.CENTER, text);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setPreferredSize(new Dimension(200, 110));
pack();
setLocationByPlatform(true);
setVisible(true);
代码示例来源:origin: stackoverflow.com
frame.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
PasteArea wrapArea = new PasteArea("Paste text here.");
frame.setLayout(new FlowLayout());
frame.add(new JScrollPane(wrapArea));
frame.pack();
frame.setVisible(true);
this.setLineWrap(true);
this.setWrapStyleWord(true);
this.setCaretPosition(str.length());
代码示例来源:origin: stackoverflow.com
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Class Design");
CreationPanel.add(instructionlabel,BorderLayout.NORTH);
inputUML.setWrapStyleWord(true);
CreationPanel.add(new JScrollPane(inputUML),BorderLayout.CENTER);
frame.add(CreationPanel);
frame.setVisible(true);
inputUML.setCaretPosition( inputUML.getText().length() );
代码示例来源:origin: stackoverflow.com
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(new BorderLayout());
txtTest = new JTextArea();
pane.setViewportView(txtTest);
this.add(pane, BorderLayout.CENTER);
txtTest.setCaretPosition(text != null ? text.length() : 0);
this.add(btnAddText, BorderLayout.SOUTH);
this.setVisible(true);
内容来源于网络,如有侵权,请联系作者删除!