List of usage examples for javax.swing JTextArea setLineWrap
@BeanProperty(preferred = true, description = "should lines be wrapped") public void setLineWrap(boolean wrap)
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); area.setWrapStyleWord(true);//www . j a va 2 s . c o m 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); c.setWrapStyleWord(false);//from ww w. j a v a2s . c o m }
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); wrapArea.setWrapStyleWord(true);/*from w w w . j a v a 2s . c om*/ 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) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel contentPane = new JPanel(); contentPane.setLayout(new GridLayout(1, 2, 2, 2)); JTextArea tArea1 = new JTextArea(); tArea1.setLineWrap(true); JTextArea tArea2 = new JTextArea(); tArea2.setLineWrap(true);/*from ww w. ja va2s . c om*/ tArea1.setText("I got a long long line of text in my JTextArea"); tArea2.setText("I got a long long line of text in my JTextArea"); JScrollPane scroller1 = new JScrollPane(); JScrollPane scroller2 = new JScrollPane(); scroller1.setViewportView(tArea1); scroller2.setViewportView(tArea2); contentPane.add(scroller1); contentPane.add(scroller2); frame.setContentPane(contentPane); frame.setSize(100, 100); frame.setLocationByPlatform(true); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JTextArea ta = new JTextArea(); ta.setLineWrap(true); Action[] actions = ta.getActions(); JMenuBar menubar = new JMenuBar(); JMenu actionmenu = new JMenu("Actions"); menubar.add(actionmenu);/*from w w w . j a v a 2 s .c om*/ JMenu firstHalf = new JMenu("1st Half"); JMenu secondHalf = new JMenu("2nd Half"); actionmenu.add(firstHalf); actionmenu.add(secondHalf); int mid = actions.length / 2; for (int i = 0; i < mid; i++) { firstHalf.add(actions[i]); } for (int i = mid; i < actions.length; i++) { secondHalf.add(actions[i]); } // Show it . . . JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(ta); f.setJMenuBar(menubar); f.setSize(300, 200); f.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); lowerPanel.add(new JScrollPane(ta)); ta = new JTextArea(content, 6, 8); ta.setLineWrap(true);//from ww w . ja v a 2 s . co m ta.setWrapStyleWord(true); lowerPanel.add(new JScrollPane(ta)); f.pack(); f.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 ww w .j a va2s . 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); ta.setWrapStyleWord(true);/*w w w . j a v a 2 s . c om*/ 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); ta.setWrapStyleWord(true);/*from w ww . jav a 2 s. com*/ 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); ta.setWrapStyleWord(true);//from w ww . j a v a 2 s.co m f.getContentPane().add(ta); f.setSize(100, 100); f.setVisible(true); }