Selasa, 14 Agustus 2012

Demo Text Area


import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class DemoTextArea {   
  public JTextArea textArea;
  public JScrollPane scroller;
               
  public DemoTextArea() {               
    textArea = new JTextArea(345,190);
    textArea.setText(
     "Ini adalah contoh string panjang " +
     "(lebih dari satu baris) " +
     "yang dimasukkan ke dalam komponen JTextArea.");
    textArea.setLineWrap(true);  //di-wrap atau dipotong
              
    scroller = new JScrollPane(textArea,
      ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
      ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroller.setLocation(0,0);
    scroller.setSize(new Dimension(345, 190));           
  }
       
  public void createAndShowGUI() {
    JFrame.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame("Demo JTextArea");
    frame.setLayout(null);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       
    frame.getContentPane().add(scroller);
               
    frame.setBounds(0, 0, 355, 200);
    frame.setLocationRelativeTo(null);

    frame.setVisible(true);
  }
   
  public static void main(String[] args) {       
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
      public void run() {
        DemoTextArea app = new DemoTextArea();
        app.createAndShowGUI();
      }
    });       
  }   
}

Tidak ada komentar:

Posting Komentar