List of usage examples for javax.swing JTextArea setWrapStyleWord
@BeanProperty(description = "should wrapping occur at word boundaries") public void setWrapStyleWord(boolean word)
From source file:TextArea.java
public static void main(String[] args) { JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea area = new JTextArea(); area.setLineWrap(true);//from ww w . ja va 2 s. com area.setWrapStyleWord(true); area.setBorder(BorderFactory.createEmptyBorder(8, 8, 8, 8)); f.add(new JScrollPane(area)); f.setSize(new Dimension(350, 300)); f.setLocationRelativeTo(null); f.setVisible(true); }
From source file:Main.java
public static void main(String[] argv) { JTextArea c = new JTextArea(); // Enable line-wrapping c.setLineWrap(true);/*from w w w . j a v a 2s. com*/ c.setWrapStyleWord(false); }
From source file:Main.java
public static void main(String argv[]) { 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);// w w w . j ava2 s. c o m wrapArea.setWrapStyleWord(true); wrapArea.setCaretPosition(testStr.length()); frame.add(new JScrollPane(wrapArea)); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { String text = "one two three four five six seven eight nine ten "; JTextArea textArea = new JTextArea(text); textArea.setColumns(30);/*from w w w .j av a2 s .c o m*/ textArea.setLineWrap(true); textArea.setWrapStyleWord(true); textArea.append(text); textArea.append(text); textArea.append(text); textArea.append(text); textArea.append(text); textArea.setSize(textArea.getPreferredSize().width, 1); JOptionPane.showMessageDialog(null, new JScrollPane(textArea), "Not Truncated!", JOptionPane.WARNING_MESSAGE); }
From source file:OffsetTest.java
public static void main(String[] args) { JTextArea ta = new JTextArea(); ta.setLineWrap(true);// w w w . jav a 2s .c om ta.setWrapStyleWord(true); JScrollPane scroll = new JScrollPane(ta); // Add three lines of text to the JTextArea. ta.append("The first line.\n"); ta.append("Line Two!\n"); ta.append("This is the 3rd line of this document."); // Print some results . . . try { for (int n = 0; n < ta.getLineCount(); n += 1) System.out.println("line " + n + " starts at " + ta.getLineStartOffset(n) + ", ends at " + ta.getLineEndOffset(n)); System.out.println(); int n = 0; while (true) { System.out.print("offset " + n + " is on "); System.out.println("line " + ta.getLineOfOffset(n)); n += 13; } } catch (BadLocationException ex) { System.out.println(ex); } // Layout . . . JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(scroll, java.awt.BorderLayout.CENTER); f.setSize(150, 150); f.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { JTextArea ta = new JTextArea(); ta.setLineWrap(true);/*from ww w . ja v a 2 s. c o m*/ ta.setWrapStyleWord(true); JScrollPane scroll = new JScrollPane(ta); ta.append("www.\n"); ta.append("java2s\n"); ta.append(".com"); try { for (int n = 0; n < ta.getLineCount(); n += 1) System.out.println("line " + n + " starts at " + ta.getLineStartOffset(n) + ", ends at " + ta.getLineEndOffset(n)); System.out.println(); int n = 0; while (true) { System.out.print("offset " + n + " is on "); System.out.println("line " + ta.getLineOfOffset(n)); n += 1; } } catch (BadLocationException ex) { System.out.println(ex); } JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(scroll, java.awt.BorderLayout.CENTER); f.setSize(150, 150); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); JTextArea ta = new JTextArea(5, 32); ta.setText("That's one small step for man...\nOne giant leap for mankind."); ta.setLineWrap(true);/*from ww w . j a va 2 s. c o m*/ ta.setWrapStyleWord(true); f.getContentPane().add(ta); f.setSize(100, 100); f.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); JTextArea ta = new JTextArea(5, 32); ta.setText("That's one small step for man...\nOne giant leap for mankind."); ta.setLineWrap(true);//from w w w.j a v a2 s .c om ta.setWrapStyleWord(true); f.getContentPane().add(ta); f.setSize(100, 100); f.setVisible(true); ((AbstractDocument) ta.getDocument()).dump(System.out); }
From source file:LineHighlightPainter.java
public static void main(String args[]) { // extend DefaultCaret as an anonymous inner class Caret lineHighlightPainterCaret = new DefaultCaret() { private Highlighter.HighlightPainter lhp = new LineHighlightPainter(); // override getSelectionPainter to return the LineHighlightPainter protected Highlighter.HighlightPainter getSelectionPainter() { return lhp; }//from w ww. java 2 s . c o m }; JFrame frame = new JFrame("LineHighlightPainter demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JTextArea area = new JTextArea(9, 45); area.setCaret(lineHighlightPainterCaret); area.setLineWrap(true); area.setWrapStyleWord(true); area.setText("This is the story\nof the hare who\nlost his spectacles."); frame.getContentPane().add(new JScrollPane(area), BorderLayout.CENTER); frame.pack(); frame.setVisible(true); }
From source file:TextAreaExample.java
public static void main(String[] args) { JFrame f = new JFrame("Text Area Examples"); JPanel upperPanel = new JPanel(); JPanel lowerPanel = new JPanel(); f.getContentPane().add(upperPanel, "North"); f.getContentPane().add(lowerPanel, "South"); upperPanel.add(new JTextArea(content)); upperPanel.add(new JTextArea(content, 6, 10)); upperPanel.add(new JTextArea(content, 3, 8)); lowerPanel.add(new JScrollPane(new JTextArea(content, 6, 8))); JTextArea ta = new JTextArea(content, 6, 8); ta.setLineWrap(true);//w ww . ja v a 2s . com lowerPanel.add(new JScrollPane(ta)); ta = new JTextArea(content, 6, 8); ta.setLineWrap(true); ta.setWrapStyleWord(true); lowerPanel.add(new JScrollPane(ta)); f.pack(); f.setVisible(true); }