+ "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));
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);
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);
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();
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);
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);
container.add(new JScrollPane(displayArea), BorderLayout.SOUTH ); displayArea.setCaretPosition(displayArea.getText().length());
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);
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());
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); } }
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);
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);
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) {
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);
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); } }
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);
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());
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() );
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);