Code :
- import javax.swing.*;
- import java.awt.BorderLayout;
- import java.awt.Container;
- import java.awt.event.ActionEvent;
- public class TestTextArea extends JFrame {
- String line = "One big, big, big, big, big, " +
- "big, big, big, big, big, " +
- "big, big, big, big, big, " +
- "big, big, big, big, big line";
- JTextArea textArea;
- public TestTextArea() {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- final Container content = getContentPane();
- textArea = new JTextArea();
- textArea.setLineWrap(true);
- textArea.setWrapStyleWord(true);
- textArea.setOpaque(true);
- textArea.setText(line);
- final JFrame frame = this;
- JButton reload = new JButton(new AbstractAction() {
- public void actionPerformed(ActionEvent e) {
- content.doLayout();
- textArea.setText(line);
- content.doLayout();
- frame.pack();
- textArea.revalidate();
- textArea.repaint();
- }
- });
- reload.setText("Reload data" );
- content.add(textArea, BorderLayout.CENTER);
- content.add(reload, BorderLayout.SOUTH);
- }
- public static void main(String[] args) {
- TestTextArea test = new TestTextArea();
- test.pack();
- test.setVisible(true);
- }
- }
|