KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > javax > swing > JTextArea

javax.swing
Class JTextArea

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.text.JTextComponent
                  extended by javax.swing.JTextArea
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable
See Also:
Top Examples, Source Code, XMLEncoder, JTextPane, JEditorPane

public void append(String str)
See Also:
insert(java.lang.String, int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1828]Subclass JTextArea
By Anonymous on 2006/09/28 15:17:45  Rate
Subclass JTextArea and overrode the append method to call super.append and then set the cursor at the end. 
  
  
 myDisplayArea = new JTextArea ( "" , 30,100 )   {  
   public void append ( String str )   {  
     super.append (  str ) ; 
     setCaretPosition (  getText (  )  .length (  )   ) ; 
    }  
  } ;


protected Document createDefaultModel()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public AccessibleContext getAccessibleContext()
See Also:
JTextComponent, Accessible
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getColumns()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected int getColumnWidth()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getLineCount()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[847]Check number of lines for a text area
By tanni { at } schnapsleiche { dot } de on 2004/08/03 14:43:33  Rate
int getSize = tArea.getLineCount (  ) ;

public int getLineEndOffset(int line)
                     throws BadLocationException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getLineOfOffset(int offset)
                    throws BadLocationException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getLineStartOffset(int line)
                       throws BadLocationException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean getLineWrap()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Dimension getPreferredScrollableViewportSize()
See Also:
JComponent.getPreferredSize(), JTextComponent, Scrollable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public Dimension getPreferredSize()
See Also:
ComponentUI, JComponent.setPreferredSize(java.awt.Dimension)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected int getRowHeight()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getRows()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean getScrollableTracksViewportWidth()
See Also:
JTextComponent, Scrollable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getScrollableUnitIncrement(Rectangle visibleRect,
                                      int orientation,
                                      int direction)
See Also:
getColumnWidth(), getRowHeight(), JScrollBar.setUnitIncrement(int), IllegalArgumentException, JTextComponent, Scrollable
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getTabSize()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getUIClassID()
See Also:
UIDefaults.getUI(javax.swing.JComponent), JComponent
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean getWrapStyleWord()
See Also:
setWrapStyleWord(boolean)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void insert(String str,
                   int pos)
See Also:
replaceRange(java.lang.String, int, int), TextComponent.setText(java.lang.String), IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public JTextArea()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public JTextArea(int rows,
                 int columns)
See Also:
IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public JTextArea(String text)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public JTextArea(String text,
                 int rows,
                 int columns)
See Also:
IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public JTextArea(Document doc)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public JTextArea(Document doc,
                 String text,
                 int rows,
                 int columns)
See Also:
IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected String paramString()
See Also:
JTextComponent
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void replaceRange(String str,
                         int start,
                         int end)
See Also:
insert(java.lang.String, int), IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setColumns(int columns)
See Also:
getColumns(), IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setFont(Font f)
See Also:
Component.getFont(), JComponent
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setLineWrap(boolean wrap)
See Also:
getLineWrap()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setRows(int rows)
See Also:
getRows(), IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setTabSize(int size)
See Also:
getTabSize()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setWrapStyleWord(boolean word)
See Also:
getWrapStyleWord()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1608]File loader form
By Anonymous on 2005/11/04 20:23:08  Rate
import java.awt.*; 
 import java.awt.event.*; 
 import javax.swing.*; 
 import java.io.*; 
  
  
 /** 
 JFC panel that provides an input field for a filename and shows the file 
 contents -- not editable. 
 */
 
 public class InputFilePanel 
     extends JPanel 
  {  
     /** 
     Constructor lays out the GUI and attach event handlers to load and save 
     the target file. 
     */
 
     public InputFilePanel  (  )  
      {  
         setLayout  ( new BorderLayout  ( 4, 4 )  ) ; 
  
  
         JPanel pnFilename = new JPanel  (  ) ; 
         pnFilename.setLayout  ( new FlowLayout  ( FlowLayout.LEFT )  ) ; 
         pnFilename.add  ( lblFilename ) ; 
         pnFilename.add  ( txFilename ) ; 
         pnFilename.add  ( ckUpdate ) ; 
         pnFilename.add  ( bnSave ) ; 
  
  
         JPanel pnContent = new JPanel  (  ) ; 
         pnContent.setLayout  ( new BorderLayout  ( 4, 4 )  ) ; 
         pnContent.add  ( BorderLayout.NORTH, lblContent ) ; 
         pnContent.add  ( BorderLayout.CENTER, new JScrollPane  ( txContent )  ) ; 
  
  
         add  ( BorderLayout.NORTH, pnFilename ) ; 
         add  ( BorderLayout.CENTER, pnContent ) ; 
  
  
         txFilename.addActionListener  ( new FileLoader  (  )  ) ; 
         bnSave.addActionListener  ( new FileSaver  (  )  ) ; 
  
  
         txContent.setFont  ( new Font  ( "Courier New", Font.PLAIN, 14 )  ) ; 
  
  
         txFilename.setToolTipText  ( "Hit ENTER to load the filename you've typed" ) ; 
         ckUpdate.setToolTipText  ( "Check this box to automatically reload the file before running a transform" ) ; 
         bnSave.setToolTipText  ( "Save the file -- overwrites any changes from an external editor" ) ; 
      }  
  
  
     public String getContent  (  )  
      {  
         if  ( ckUpdate.isSelected  (  )  )  
             load  (  ) ; 
  
  
         return txContent.getText  (  ) ; 
      }  
  
  
     /** 
     Loads the file named in  { @link #txFilename }  into  { @link #txContent } . 
     */
 
     public void load  (  )  
      {  
         try 
          {  
             InputStream in = new FileInputStream  ( txFilename.getText  (  )  ) ; 
             int c = -1; 
             StringBuffer buffer = new StringBuffer  (  ) ; 
             while  (  ( c = in.read  (  )  )  != -1 )  
                 buffer.append  (  ( char )  c ) ; 
  
  
             txContent.setText  ( buffer.toString  (  )  ) ; 
  
  
             in.close  (  ) ; 
          }  
         catch  ( IOException ex )  
          {  
             System.out.println  ( "Couldn't load file." ) ; 
          }  
      }  
  
  
     /** 
     Sets the passed filename into  { @link #txFilename }  and delegates to 
      { @link #load (  )  load } . 
     */
 
     public void load  ( String filename )  
      {  
         txFilename.setText  ( filename ) ; 
         load  (  ) ; 
      }  
  
  
     /** 
     Saves the contents of  { @link #txContent }   ( back )  to the file named 
     by  { @link #txFilename } . 
     */
 
     public void save  (  )  
      {  
         try 
          {  
             OutputStream out = new FileOutputStream  ( txFilename.getText  (  )  ) ; 
             String content = txContent.getText  (  ) ; 
             for  ( int c = 0; c  <  content.length  (  ) ; ++c )  
                 out.write  (  ( char )  content.charAt  ( c )  ) ; 
             out.close  (  ) ; 
          }  
         catch  ( IOException ex )  
          {  
             System.out.println  ( "Couldn't save file." ) ; 
          }  
      }  
  
  
     /** 
     Event handler for  { @link #txFilename }  -- delegates to 
      { @link load (  )  load } . 
     */
 
     private class FileLoader 
         implements ActionListener 
      {  
         public void actionPerformed  ( ActionEvent ev )   {  load  (  ) ;  }  
      }  
  
  
     /** 
     Event handler for  { @link #bnSave }  -- delegates to 
      { @link save save } . 
     */
 
     private class FileSaver 
         implements ActionListener 
      {  
         public void actionPerformed  ( ActionEvent ev )   {  save  (  ) ;  }  
      }  
  
  
     private JLabel lblFilename = new JLabel  ( "Filename:" ) ; 
     private JTextField txFilename = new JTextField  ( 18 ) ; 
     private JCheckBox ckUpdate = new JCheckBox  ( "Auto-update on transform" ) ; 
     private JButton bnSave = new JButton  ( "Save" ) ; 
  
  
     private JLabel lblContent = new JLabel  ( "Content:" ) ; 
     private JTextArea txContent = new JTextArea  (  ) ; 
  }  
  
  
 

Popular Tags