List of usage examples for javax.swing JTextArea append
public void append(String str)
From source file:Main.java
public static void main(String[] argv) { JTextArea ta = new JTextArea("Initial Text"); ta.append("some text"); }
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 a v a 2 s . c om*/ 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:ScrollPaneWatermark.java
public static void main(String[] args) throws Exception { JFrame frame = new JFrame(); JTextArea ta = new JTextArea(); for (int i = 0; i < 1000; i++) { ta.append(Integer.toString(i) + " "); }//w w w . ja v a 2 s. c o m ta.setLineWrap(true); ta.setWrapStyleWord(true); // ta.setOpaque(false); ScrollPaneWatermark watermark = new ScrollPaneWatermark(); watermark.setBackgroundTexture(new File("background.jpg").toURL()); watermark.setForegroundBadge(new File("foreground.png").toURL()); watermark.setView(ta); JScrollPane scroll = new JScrollPane(); scroll.setViewport(watermark); frame.getContentPane().add(scroll); frame.pack(); frame.setSize(600, 600); frame.setVisible(true); }
From source file:PrintUIWindow.java
public static void main(String args[]) { UIManager.put("swing.boldMetal", Boolean.FALSE); JFrame f = new JFrame("Print UI Example"); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0);/*from w w w. j a va 2 s. c o m*/ } }); JTextArea text = new JTextArea(50, 20); for (int i = 1; i <= 50; i++) { text.append("Line " + i + "\n"); } JScrollPane pane = new JScrollPane(text); pane.setPreferredSize(new Dimension(250, 200)); f.add("Center", pane); JButton printButton = new JButton("Print This Window"); printButton.addActionListener(new PrintUIWindow(f)); f.add("South", printButton); f.pack(); f.setVisible(true); }
From source file:MainClass.java
public static void main(String[] args) { JTextArea ta = new JTextArea(); ta.setLineWrap(true);//from w w 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) { JTextArea cmp = new JTextArea(); String str = "a"; for (int i = 0; i < 20; i++) { cmp.append(str + str + "\n"); }//from w w w .j a va 2 s . co m JScrollPane scrollPane = new JScrollPane(cmp); scrollPane.setComponentZOrder(scrollPane.getVerticalScrollBar(), 0); scrollPane.setComponentZOrder(scrollPane.getViewport(), 1); scrollPane.getVerticalScrollBar().setOpaque(false); scrollPane.setLayout(new ScrollPaneLayout() { @Override public void layoutContainer(Container parent) { JScrollPane scrollPane = (JScrollPane) parent; Rectangle availR = scrollPane.getBounds(); availR.x = availR.y = 0; Insets parentInsets = parent.getInsets(); availR.x = parentInsets.left; availR.y = parentInsets.top; availR.width -= parentInsets.left + parentInsets.right; availR.height -= parentInsets.top + parentInsets.bottom; Rectangle vsbR = new Rectangle(); vsbR.width = 12; vsbR.height = availR.height; vsbR.x = availR.x + availR.width - vsbR.width; vsbR.y = availR.y; if (viewport != null) { viewport.setBounds(availR); } if (vsb != null) { vsb.setVisible(true); vsb.setBounds(vsbR); } } }); scrollPane.getVerticalScrollBar().setUI(new MyScrollBarUI()); JFrame f = new JFrame(); f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); f.getContentPane().add(scrollPane); f.setSize(320, 240); f.setVisible(true); }
From source file:OffsetTest.java
public static void main(String[] args) { JTextArea ta = new JTextArea(); ta.setLineWrap(true);//from www. j a v a2 s.com 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:Main.java
public static void main(String[] args) { JFrame f = new JFrame(); JTextArea textArea = new JTextArea(); f.add(new JScrollPane(textArea), BorderLayout.CENTER); Timer timer = new Timer(1000, new ActionListener() { @Override/*from w w w .j av a 2 s . c om*/ public void actionPerformed(ActionEvent e) { textArea.append("bla"); } }); timer.setRepeats(true); timer.start(); JButton button = new JButton("Click me"); button.addActionListener(e -> { System.out.println("Before option pane"); JOptionPane.showMessageDialog(f, "A message dialog"); System.out.println("After option pane"); }); f.add(button, BorderLayout.SOUTH); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.pack(); f.setVisible(true); }
From source file:EditComboBox.java
public static void main(String args[]) { String labels[] = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J" }; JFrame frame = new JFrame("Editable JComboBox"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container contentPane = frame.getContentPane(); final JComboBox comboBox = new JComboBox(labels); comboBox.setMaximumRowCount(5);//from w w w .ja v a 2 s . com comboBox.setEditable(true); contentPane.add(comboBox, BorderLayout.NORTH); final JTextArea textArea = new JTextArea(); JScrollPane scrollPane = new JScrollPane(textArea); contentPane.add(scrollPane, BorderLayout.CENTER); ActionListener actionListener = new ActionListener() { public void actionPerformed(ActionEvent actionEvent) { textArea.append("Selected: " + comboBox.getSelectedItem()); textArea.append(", Position: " + comboBox.getSelectedIndex()); textArea.append(System.getProperty("line.separator")); } }; comboBox.addActionListener(actionListener); frame.setSize(300, 200); frame.setVisible(true); }
From source file:Main.java
public static void main(String[] args) { JProgressBar pb = new JProgressBar(); JTextArea ta = new JTextArea(10, 20); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new JScrollPane(ta)); frame.add(pb, BorderLayout.SOUTH); frame.pack();// w w w . j a va 2 s . c o m frame.setVisible(true); Timer timer = new Timer(250, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { index++; if (index >= 100) { ((Timer) (e.getSource())).stop(); } ta.append("Line " + index + "\n"); pb.setValue(index); } }); timer.setRepeats(true); timer.setCoalesce(true); timer.start(); }