How to  make JTextArea rows and colums auto-increase?

My test program is attached as below.
The JTextArea can not enlarge itself when the text in a line is too long that some characters are hidden.When rows grows too many will also see the problem.
How can I make the rows and columns auto-increase to meet the width or height of my text?
-----My Test Demo----
import java.awt.*;
import java.awt.event.*;
import java.awt.color.*;
import javax.swing.*;
public class Test{
public static void main(String[] args){
JFrame f = new JFrame("My Editor");
Container ct = f.getContentPane();
JPanel jp = new JPanel();
JTextArea ta = new JTextArea("My software.",10,30);
JTextArea ta2 = new JTextArea("Hello,World!",10,30);
jp.setPreferredSize(new Dimension(400,400));
jp.setBackground(Color.green);
jp.setLayout(null);
jp.add(ta);
ta.setBounds(100,100,150,200);
ta.setOpaque(false);
ta.setBorder(null);
jp.add(ta2);
ta2.setBounds(100,120,150,200);
ta2.setOpaque(false);
ta2.setBorder(null);
// jp.addMouseListener(new MyMouseListener());
ct.setLayout(new BorderLayout());
ct.add(jp,BorderLayout.CENTER);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent evt) {
System.exit(0);
f.setVisible(true);
f.pack();

This link to the Java Swing tutorial will show you how to add the JTextArea to a JScrollPane:
http://java.sun.com/docs/books/tutorial/uiswing/components/simpletext.html#textarea
It appears to me that you are new to Swing so you should read the entire tutorial "Creating a GUI using JFC/Swing" before asking any more question. The tutorial can be read online or downloaded from:
http://java.sun.com/docs/books/tutorial/
The download link for all tutorials on this page is near the bottom.

Similar Messages

  • How to limit JTextArea Rows and Coloums

    Hello
    I am using JTextArea inside JScrollPane
    I want to limit the maximum number of lines possible and the maximum chars in each line.
    I tried to limit the lines but i don't know exactly how many lines do i have because of the line wrapping,
    The line wrapping is starting new line in the screen but in the string of the component it is really the same line with no '\n' to indicate new line.
    I need that the string will be exactly like on the screen, each line will end with '\n' (if there another line after it) and the user will be able to insert only X lines and Y chars in each line.
    Does anyone have an idea?
    Thank you in advance
    Yuval

    I wrote something similar but it is not enough
    This is good only for the lines and not for the max chars in the lines
    I tried something like this in class that extended the DefaultStyledDocument and :
    private JTextArea textArea ;
    textArea  = new JTextArea(3,19);
    textArea  .setLineWrap(true);
    textArea .setDocument(new LimitedStyledDocument(3));
    JScrollPane scrollPane  = new JScrollPane(textArea );
    public class LimitedStyledDocument extends DefaultStyledDocument {
        /** Field maxCharacters */
        int maxLines;
        public LimitedStyledDocument(int maxLines) {
            maxCharacters = maxLines;
    public void insertString(int offs, String str, AttributeSet attribute) throws BadLocationException {
        Element root = this.getDefaultRootElement();
        int lineCount = getLineCount(str);
        if (lineCount + root.getElementCount() <= maxLines){
            super.insertString(offs, str, attribute);
        else {
            Toolkit.getDefaultToolkit().beep();
    * get Line Count
    * @param str
    * @return the count of '\n' in the String
    private int getLineCount(String str){
         String tempStr = new String(str);
         int index;
         int lineCount = 0;
         while (tempStr.length() > 0){
              index = tempStr.indexOf("\n");
              if(index != -1){
                   lineCount++;
                   tempStr = tempStr.substring(index+1);
              else{
                   break;
         return lineCount;
    }Thats work just fine but still not enough
    I tried to set also maxCharsInLine to count the chars in similar way but it is to complicated and there is a lot of problems with it
    Thank you, but still waiting for an answer

  • How to check all rows and colums runtime executing BW query

    Hi Guys,
    I have a BW query with many calculated key figures. while execute this query the performance is really bad/slow. I need to know in which object the query is taking long time, is there any table or anything to get this information. I have looked all the query perfomation stuffs, everything looks good, just want to figure out what is making OLAP runtime longer.
    Thanks,
    Kris

    Hi Krish,
    You can not check the time taken by any particular key figure/ characteristics.
    However, if you really want to reduce the time, you can create aggregates proposed by SAP based on your query.
    First go to RSRT, place your query and click on "Execute + Debug".
    Then select "Display Aggregate Found" under Aggs and "Display Statistics Data" under Others in the "Debug Options".
    Now it will show you how you should create your aggregate based on different objects so that the total query execution time will be less.
    Also after clicking on BACK button you can check the time taken by each event during Query execution.
    Hope it helps.
    Thanks,
    Subrat.

  • How to make the row as a hyperlink in Crystal 2008

    Hi,
    Could you give me advise on how to make the row as a hyperlink and call another report.
    Thank you in advance.
    Rose

    Hi Sastry,
    I was able to create the subreport and its working.
    Thank you so much.
    Regards.
    Rose

  • How to make first row as selected in af:table

    Hi,
    I am using JDeveloper 11.1.1.4 and ADF-BC in my application.
    In all the pages across my application we have multi select enabled for the table[af:table].
    But when the pages are displayed,the first row is not selected by default.
    My requirement is to display first row as selected across all the tables in my app.
    I have the selectionListenerset as for example selectionListener="#{bindings.RSCMapVO2.collectionModel.makeCurrent}" in all the pages.
    Please suggest on how to make first row as selected.
    Regards,
    Praveen

    Hi
    Put these codes in your selection listner method(You have to define a selectionListner method in your backing bean and put this code segment
    (Special thanks go to Franks how posted this code segment. threadID=1089583)
    RichTable yourTable = (RichTable) selectionEvent.getSource();
    //the Collection Model is the object that provides the structured data
    //for the table to render
    CollectionModel yourTableModel = (CollectionModel) yourTable.getValue();
    //the ADF object that implements the CollectionModel is JUCtrlHierBinding. It
    //is wrapped by the CollectionModel API
    JUCtrlHierBinding yourTableBinding = (JUCtrlHierBinding) yourTableModel.getWrappedData();
    //Acess the ADF iterator binding that is used with ADF table binding
    DCIteratorBinding yourTableIteratorBinding = yourTableeBinding.getDCIteratorBinding();
    //the role of this method is to synchronize the table component selection
    //with the selection in the ADF model
    Object _selectedRowData = yourTable.getSelectedRowData();
    //cast to JUCtrlHierNodeBinding, which is the ADF object that represents
    //a row
    JUCtrlHierNodeBinding nodeBinding = (JUCtrlHierNodeBinding) selectedRowData;
    //get the row key from the node binding and set it as the current row in the
    //iterator
    Key rwKey = nodeBinding.getRowKey();
    tableIteratorBinding.setCurrentRowWithKey(rwKey.toStringFormat(true));
    Thanks
    Padma

  • HT4642 ios numbers:how to make cell height variable with auto line brake setting ?

    ipad numbers; How to make cell height variable with auto line break setting?

    That's strange. I responded earlier and the whole message got trashed. Hence the test post before retyping the entire thing again.
    Thanks for the reply.
    The video clip is a single screen capture video clip. This is what I've found by playing around with this more.
    The original clip resolution is greater than 640x480. If I use QT Pro to convert the original clip to 640x480 and then use either Flip4Mac or PE7, then the resolution looks good.
    Just trying to figure out if should keep all workflow on the MacOS side. There are several different version of Flip4Mac. $49 gives me 640x480, but if I ever want to make it slightly larger then I would need to go with the $99 or HD version.
    I also tried to export to AVI with QT Pro and the import with Windows MovieMaker but it didn't work really good. I liked the simplicity (since PE7 hogs a lot of resources especially through VMWare).

  • How to add new row and update existing rows at a time form the upload file

    hi
    How to add new row and update existing rows at a time form the upload file
    example:ztable(existing table)
    bcent                      smh            nsmh         valid date
    0001112465      7.4                       26.06.2007
    0001112466      7.5                       26.06.2007
    000111801                      7.6                       26.06.2007
    1982                      7.8                       26.06.2007
    Flat file structure
    bcent                       nsmh         valid date
    0001112465     7.8     26.06.2007  ( update into above table in nsmh)
    0001112466     7.9     26.06.2007  ( update into above table in nsmh) 
    000111801                     7.6      26.06.2007 ( update into above table in nsmh
    1985                      11              26.06.2007   new row it should insert in table
    thanks,
    Sivagopal R

    Hi,
    First upload the file into an internal table. If you are using a file that is on application server. Use open dataset and close dataset.
    Then :
    Loop at it.
    *insert or modify as per your requirement.
    Endloop.
    Regards,
    Srilatha.

  • How to make Sales group and office field mandatory in VA01 first screen

    hi gurus,
    can anybody tell me how to make Sales group and sales office mandatory field on VA01 tcode first screen. i have requirement to make it compulsary on the first screen otherwise they wont be able to goto next screen.
    will reward points for sure
    thanks
    mandy

    Hi! Mandy,
    Try using t.code SHD0, choose your transaction variant here, further choose your screen variant.
    Next select your screen variant and in the Menu bar select Variant> change with processing>Make repairs in foreign namespaces only if they are urgent> Continue(Enter)>again 'enter'>Object can only be created in SAP package>continue(enter)> Exit and save >This variant contains other screens, adopt these as well?>enter>enter> scroll down to the entry required by you make the necessary changes(Output only, invisible or required) and save.
    The system will prompt to assign a package and request enter the necessary values.
    Provide your feedback.
    Regards,
    PATHIK

  • How to make the dblink and what is the use of this

    plz any body tell me "how to make the dblink and what is the use of this"
    sujit

    Do you understand how to make the Slider work using code to read its value?  You will need to look into that in order to do this.
    What you can do is have the yello rectangle be a movieclip that sits over the red rectangle and use the Slider to control the yellow rectangle's alpha property from 0 to 1.  That way the yellow will gradually fade as you slide.
    What you will then need  to do is figure out how to make the number of dots that appear reduce from 15 to 8 over the same range of the slider.  You need to use the fractional value from the slider to decide how many dots either appear or do not appear.
    You should not start new postings for the same topics that you arlready have postings for.  Doing so in the future might result in them being removed.

  • How to make New Document and Upload Document to have same Content Type in Document Library in Sharepoint 2010

    Hi,
    How to make 'New Document' and 'Upload Document' to have same content type(Custom) in Document Library in Sharepoint2010.
    Note : I have created custom Content Type since I have custom columns along with upload column..
    Regards, Shreyas R S

    go to library settings 
    Change new button order and default content type
    set your custom content type to be #1
    when you upload new document it will automatically have your custom content type
    Hope that helps|Amr Fouad|MCTS,MCPD sharePoint 2010

  • How can I preserve row and column addresses on multiple cells at once in Numbers?

    How can I preserve row and column addresses on multiple cells at once in Numbers 3.2.2? I do a lot of rearranging and sorting and want to reference cells in other sheets. After entering the formulas (example: '=Sheet1::Table 1::H126') I will sort the table and the formulas will not move with the sort.  I think I can fix this by going cell by cell checking the 'preserve row' and 'preserve column' boxes when editing the formula.  I want to avoid having to go one by one.  I know that checking the boxes creates a formula like this: '=Sheet1::Table 1::$H$126'  I have also tried entering this manually and filling down but it doesn't include the preservations (the $$) in the autofill.  If there is another way to remedy my sorting problem that would also be welcomed!
    THANKS!!

    The title of the post is this
    How can I preserve row and column addresses on multiple cells at once in Numbers?
    I restated the Question as follows
    Can "Preserve Row" an / or "Preserve Column" be set on multiple cells at the same time.
    In both cases it is not asked if multiple cells can be set to....
    That is a given.
    Step back a second...  It is like selecting multiple cells and setting the text color of the currently selected cells to red. This can be done. More than one cell at a time modified because they are currently selected.
    Whats is being asked is:  if more than one cell is selected at the same time can the settings "Preserve Row" an / or "Preserve Column" be applied. No table I put up will help with that question.
    YES or NO
    If YES how?

  • Interchanging rows and colums of internal table

    Hi all,
    I have one requirement to interchange the rows and colums of 3X3 internal table.(internal table contains 3 rows and 3 columns ). In the new internal table, I have to display the rows as column values and column values as rows..
    It's urgently. Kindly send me the sample code for the same.
    Thanks in advance.
    Ramesh.

    Hi ramesh,
    it is not possible to create a 'transponed' internal table if the (2) fields in your table arte or different type. Thus each row of the new table would be of different type.
    The quick solution for display is
    field-symbols:
      <any> type any.
    do.
      loop at itab.
        assign component sy-index of structure itab to <any>.
        if sy-subrc <> 0.
    * not assigned means no more components
          exit.
        endif.
        write <any>.
      endloop.
      if sy-subrc = 0.
    * start a new line for the next field
        write /.
      else.
    * all done
        exit.
      endif.
    enddo.
    If you really want to store the values in transposes table, you could do so by storing their references in fields of type REF TO DATA because this is good for any data.
    possible usage:
    types:
      ty_t_reftab type standard table of ref to data with default key,
      ty_t_transposed type standard table of ty_t_reftab with default key.
    data:
      lt_transposed type ty_t_transposed,
      lv_ref type ref to data.
    field-symbols:
      <any> type any,
      <transposed> type line of ty_t_transposed
    do.
      loop at itab.
        at first.
          append initial line to lt_transposed assigning <transposed>.
        endat.
        assign component sy-index of structure itab to <any>.
        if sy-subrc <> 0.
    * not assigned means no more components
          exit.
        endif.
        get refernce of <any> into lv_ref.
        append lv_ref to <transposed>. 
      endloop.
      if sy-subrc <> 0.
    * all done
        exit.
      endif.
    enddo.
    read table
    Sorry, don't know what it's good for. If you need the values, access them like
    loop at lt_transposed assigning <transposed>.
      loop at <transposed> assigning <any>.
        write <any>->*. "Hope that works with WRITE
      endloop.
    endloop.
    Regards,
    Clemens

  • How to make your iPad and iPhone commicate with each other

    How to make your iPad and iPhone commicate with each other

    this is very easy...
    firstly disconnect the DSL modem for the linksys..
    then connect the computer to the linksys router (port 1/2/3/4)..
    then access the linksys setup UI
    open ur web browser
    site: http://192.198.1.1/
    username: [blank]
    password: admin
    now hook up the westell modem.. and goto the status page ...
    check Internet IP.
    if then Internet IP is 192.168.1.* then,
    disconnect the westell from the router and goto the setup page.
    change the LOCAL IP address to 192.168.2.1 (notice the 2.1 and not 1.1)
    save settings....
    connect the westell and viola ur online...
    if the Internet IP is 0.0.0.0 then
    goto the setup page and change the 'Internet connection Type' to 'PPPoE'
    once done the page changes and give u a place to enter a username and a password.. this username and password is given by verizon..
    sud be something like '[email protected]'
    once done save settings...
    goto the status page and hit connect... give it a few moments... u shud get a Internet ip address... if u get one ur online if not then power cycle the entire network. and try check to see if u get an ip..
    hope this helps...
    cheers..
    Life is short... So get movin !!!
    DopeLorD

  • How to make own editor and call it?

    could you please tell me how to make own editor and call it on a clicking of a push button corresponding to an test Item

    In the Object Navigator... just click on the 'Editor' Node and press the '+' (Create) button....
    Set then any properties as you like....
    So simple...
    Greetings,
    Sim

  • How to make an ebook and sell it on the ibook or app store??

    How to make an ebook and sell it on the ibook or app store??
    Can anybody help me please T^T
    By the way I'm in Thailand and want to sell my ebook around the world.
    This is my dream ^^.. Help me please...

    Hi,
    Start with the ADC iOS dev center here.
    http://developer.apple.com/devcenter/ios/index.action
    Carolyn

Maybe you are looking for

  • Gl account tab needs to be editable mode in Miro hear level

    Dear Team, Please let m eknow how i will make the editable mode for the GL field in the MIRO hear level.Please let me know the implications by doing this. Thanks for the consideration. Regards, Suma

  • How to add highlight mark to video?

    I'm a novice video editor. I need to produce a sports video, and I need to highlight an individual player by putting a circle, an arrow, or some other type of highlight around the individual player for a second or two. Anyone know how to do this? I k

  • Azure Management REST API for Azure Cache ?

    Can't find restful azure management API to create Azure Cache ? looks like only way to create Azure Cache via Azure Portal ? Max

  • Problem with earphone when plug in Ethernet cable!!!

    Hi guys, I bought the macbook pro 15 couple days ago. And I realize that whenever I use my Ethernet cable, my earphone has strange sound, so I unplug the earphone and plug it back, it's ok, but after few minutes (when I play a song) I hear that sound

  • Auzentech X-Fi prelude and X-fi I/O dr

    I looked at this card and I noticed?- it has an internal 40 pin AD-Link header!? That means that a X-fi I/O dri've should work with this card. But does it's? I want it to work so bad I might take one for the team. I've always wanted a dri've bay modu