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

Similar Messages

  • 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.

  • 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 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?

  • How to Increase the Rows and Columns Size of Bex Query in Enterprise Portal  of SAP  7.3

    Dear All,
    Please let me know the process how to Increase the Rows and Columns  Size of Bex Query in Enterprise Portal  of SAP  7.3 .
    Currently I am getting Only  4 columns and 10 rows in One Page .And I am getting 1,2 etc tabs for both row and column. So i want to increase the column length more than 100  and row length more than 10000.
    Please suggest me a suitable solution to over come this issue.
    Please find the Below screen shot.
    Thanks
    Regards,
    Sai

    Dear All,
    Please find the attached screen shot.
    The report be open with 4 or 5 columns and 5 or 6 rows.
    So, please  let me know how to increase the length of the table.
    Do the needful for me to over come this issue.
    Thanks
    Regards,
    Sai.

  • How to increase the row and Column length of Bex query in EP Portal 7.3

    Dear All,
    Please let me know the process  to Increase the Rows and Columns  Size of Bex Query in Enterprise Portal  of SAP  7.3 .
    Please  let settings to increase rows up 10000 and column 100 in one page.
    Thanks
    Regards,
    Sai

    Dear All,
    Please find the attached screen shot.
    The report be open with 4 or 5 columns and 5 or 6 rows.
    So, please  let me know how to increase the length of the table.
    Do the needful for me to over come this issue.
    Thanks
    Regards,
    Sai.

  • Error loading from csv - how to integrate valid rows and drop invalid?

    Hello,
    Log from execution (step: load csv data):
    ODI-1228: Task SrcSet0 (Loading) fails on the target ORACLE connection ODI_STAGE.
    Caused By: java.sql.BatchUpdateException: ORA-12899: wartość zbyt duża dla kolumny "ODI_STAGE"."C$_0URZADZENIA"."C1_ZWIAZKI" (obecna: 17, maksymalna: 6)
    So, it's clear. There are too long fields in csv, maximum is 6, current: 17. But, some rows are good (with ZWIAZKI lenght >=6). I need to load valid rows, integrate them, sent to destination table. Invalid rows should be isolated in external csv - it happens. But how can I integrate valid rows and prevent entire interface fail?

    I don't think something exists to really be prepared for every situation (invalid length, invalid format, ...).
    Here is an idea but it's not beautifull and I'm not sure it's the good way to do that :
    -First you should have a unique key (easier if it is on only one column).
    -Then Develop an new IKM to insert on a row-by-row insert/commit basis with an ORDER BY clause on the UK in the select. Before the insert step, the value of the UK for the current row should be stored in an ODI variable.
    -Create your interface and put a filter on your UK : UK_FIELD > :CURRENT_UK
    -Create a package, set CURRENT_UK to a value you know will be less than the possible min and refresh a new variable MAX_UK with a query to find the MAX(UK_FIELD). Then put your interface in the package and do a loop around it so it ends only when CURRENT_UK = MAX_UK. You should redirect both OK and KO arrows from the interface to the testing condition.
    @Phil : Sorry for "stealing" your reply :P. Nice to see you agree with me.

  • How can I print row and column headings?

    In AW6 I was able to select Appleworks in the print window and check if I wanted to print row and/or column headings. I have not been able to find how to do this in Numbers. Can anyone tell me how?
    Paco

    Paco wrote:
    I have not been able to find how to do this in Numbers.
    Perfectly logical, the feature is unavailable.
    Workaround:
    Use a row header and a column header to mimic the missing feature.
    In cell B1 I entered
    =CHAR(CODE("A")-1+COLUMN())
    and applied fill to the right
    CAUTION, this formula is OK only from colum B thru column Z.
    In cell A2 I entered
    =ROW()
    and applied Fill Down
    Then convert column A as header one
    convert row A as header one.
    Yvan KOENIG (from FRANCE dimanche 22 février 2009 12:28:34)

  • How to stop "Add Row" and "Delete" from committing.

    Hello, I am new to Application Express, and maybe someone can help me make this save like an Oracle Form.
    If you hit the "Add Row" button, enter data, then hit the "Add Row" button again, it commits the first row. If you check a value and hit the "Delete" button, it commits the delete. I would like the insertions and deletes to be handled like an update, that is with an explicit commit by hitting the "Apply Changes" button.
    Can I control this in Application Express, and how?
    Thank you,

    Kevin,
    1. instead of having a form on a table, you would create a form on a collection,
    2. collection is also a table but it is only of a temporary nature - it is valid with the corresponding session. Once the session is closed, you can't access the collection.
    3. to see how to create a collection and a tabular form use this example:
    http://htmldb.oracle.com/pls/otn/f?p=31517:176
    4. add row and delete will add / delete a copy of your table data. You can then create a process to save the data in your target table only if the button apply changes is clicked.
    Denes Kubicek
    http://deneskubicek.blogspot.com/
    http://www.opal-consulting.de/training
    http://apex.oracle.com/pls/otn/f?p=31517:1
    -------------------------------------------------------------------

  • How to layout constraint rows and columns "right"?

    Hi.
    I have a complex constraint layout with 8 columns and 11 rows. Since this layout is not an MXML-file, I need to do it in actionscript. Is there a "best pratice" on how to layout this without the Design view in Flash Builder?
    Is it possible to display the columns and rows like in HTML, where I could say "border=1" or use css?
    Regards,
    Jo

    What makes you think that it is not there? Any form which doesn't have the same set of members across rows and dimensions are asymmetric.
    Asymmetric rows and columns contain different sets of members selected across the same dimensions
    Oracle Hyperion Planning, Fusion Edition Administrator's Guide
    I can add a column with only Q1 and then another column with Q2, Q3, Q4 which will make it an asymmetric form. Keep in mind not to check "Place selection in separate columns".
    Regards
    Celvin
    http://www.orahyplabs.com

  • Doubt on Rows and Coloums in BEx Query Designer.

    Hello, Experts.
    I have a Doubt in BEx Query Designer.
    In the Rows I have a Fiscal year Period,  if the user enters the Fiscal year period for e.g. : 001/2006  .  
    in the columns i have  forecast for the Fiscal year period which user entered ( 001/2006 ),   and we have another column pervious ( Prior )fiscal year period ( 001/2005 ). 
    My Questions is ,  as we are Restricting with 001/2006 will the query retrieve the values of 2005 or not?
    Thanks in Advance .
    Sharp

    yes i am  Doing Offest.
    I moved this Fiscal year Period to Free char,   and i Restricted with Pervious Fical Year period and Fical year period .  it worked.  but
    when i kept this in Rows and deleted Previous Fiscal Year period .  it is displaying blanks.   in prior years forecast.
    is it because i am Ristricting it to only fical year period  which user entered
             Colums-->  Forcast ( User Entered year )          Prior year
    Rows
    Fiscal year period
      Fiscal year period( user enterd )
    Thanks

  • How to preserve a row and column in numbers automatically.ie the cells are not consecutivecell a1 a3 etc

    working on a league table
    when sorting the league table ,I need to preserve the row and column
    I can preserve row and column by using the drop down menu on every cell,but would like to do it automatically(2 clicks to every cell)
    working in numbers
    yosemite 10.2

    This technique would be quite slow. Unfortunately, it's the only way I could think of if it's really an Excel file. If it's tab delimited file, you could read a whole thing into 2D array and work on Array instead of reading cell-by-cell.

  • How to know the row and col numbers of a cell in JTable at mouseclicked

    Hi, I'm coding an app using swing and JTable, in this table I will display the records from a database, now, each time the user has click in any cell I want to display it value, whit this method:
        private void setpuntero(JTable table, int row, int col){
            Object o = table.getValueAt(row, col);
            System.out.println("Valor de la celda: "+o.toString());
    }The mouseclick event was coded like this:
                table.addMouseListener(new MouseAdapter() {
                    public void mouseClicked(MouseEvent e) {
                        setpuntero(table, 1, 3);
                });My question is:
    how in the mouseClicked I can pass to setpuntero() method the dynamic values of the cell that the user clicked?
    In this example, setpuntero(table, 1, 3); I have chosen the cell(1,3) to display the value, but really I don't know how to capture those values dinamically using the mouse click
    Regards
    Herbert

    perhaps:
          public void mouseClicked(MouseEvent e)
            int row = table.getSelectedRow();
            int col = table.getSelectedColumn();
            String selected = table.getValueAt(row, col).toString(); // this will need to be changed if not String data
          }

  • How to lock a row and release lock

    Hello
    There are two thread, they read the same row, I want to lock this row when the first thread read the record, after this thread commit its data, release the lock, the second thread can lock this record, also can commit its data. I also want to know how to release the lock. And these operations are in different Classes, e.g. in Class A first thread lock the record, in Class B second lock the record, and in Class C release the lock.
    Note: these two thread will read this record at same time.
    Thanks in advance.

    TopLink provides to forms of locking, optimistic and pessimistic.
    <p>
    You are referring to pessimistic. You can use pessimistic locking in TopLink through the ReadObject/ReadAllQuery API acquireLocks(), or acquireLocksWithoutWaiting(), this will use a "Select ... for Update" in SQL. You must be in a transaction to lock a row in the database (UnitOfWork in TopLink), and you locks are released when you commit or rollback the transaction. If you are using JPA, TopLink supports a JPA query hint "toplink.pessimistic-lock"="Lock" to allow pessimistic locking.
    <p>
    You can also use optimistic locking. An optimistic lock does not prevent another user from reading the same row, but ensures that only one user will be able to commit changes to the row. Optimistic locking typically has the advantage of better concurrency, and does not have issues with deadlocks.
    <p>---
    <br>James Sutherland
    <br>Oracle TopLink, EclipseLink
    <br>Wiki: Java Persistence, EclipseLink

  • How to get the Row and Column values in ALV (without using Objects)

    Hi All,
    I need to get the Row / Column when double click is used in ALV, I can use the double click event for this. However, I do not want to use the Object Oriented ALV. I want to implement the same functionality using general (using functions) ALV.
    Is there any way to get the row / column values for a Generia (non-OOPs) ALV report.
    Please help.
    Thanks,
    Vishal.

    Hello,
    The only think you have to do is to get the index where the user clicked, and then read the internal table you sent to the alv
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program       = 'prg_name'
          i_callback_pf_status_set = 'SET_PF_STATUS'
          i_callback_user_command  = 'USER_COMMAND' " this is to the click event!!
          i_callback_top_of_page   = 'TOP_OF_PAGE'
          is_layout                = alv_layout
          it_fieldcat              = alv_fieldcat
          i_save                   = 'A'
          it_events                = alv_events[]
        TABLES
          t_outtab                 = i_totmez.  ---> TOUR IT.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
              WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    " then....
    FORM user_commandUSING r_ucomm     TYPE sy-ucomm
                                    ls_selfield TYPE slis_selfield.
    " r_ucomm -> HAS THE STATUS
    " ls_selfield-tabindex  -> HAS THE SELECTED INDEX
    " THEN READ THE INTERNAL TABLE
    " HERE YOU WILL HAVE THE SELECTED ROW
    READ TABLE i_totmez INDEX ls_selfield-tabindex.
    ENDFORM.
    cheers,
    Gabriel P.

Maybe you are looking for

  • Substituting Cost of Goods Sold Account Profit Center

    Hi I am using Sales Order substitution to change the Profit Center according to Sales Org + Product Hierarchy + Customer Group + Acct Asst Grp.  This perfectly replace the Profit Center in Sales Order.  The Profit Center from Sales Order is perfectly

  • Notes are not being Saved

    Recently upgraded to an iPhone 3G S from the first generation iPhone. Synced my phone and everything is fine, but when I use the Notes application the notes are not being saved. Anyone know of a way to fix this?

  • Libreoffice mime-type icons

    Hi, i'm curious to know if i'm the only that have ugly mime-type icons for LibreOffice files (.odt .doc .ods ...) Before I like to see the original LibreOffice mime-type icons, so after a lot of research on the web i've found the solution. Following

  • Smartforms Bill of lading.

    Hi all, (bol Delivery) 1. Is LE_SHP_DELNOTE SMARTFORMS IS FOR BILL OF LADING? 2. I HAVE USED LE_SHP_DELNOTE AND COPIED INTO ZLE_SHP_DELNOTE AND DEVELOPED SMARTFORMS FOR BOL. AND I AM USING THE EXISTING DRIVER PROGRAM RVADDN01. THE EXISTING DRIVER PRO

  • Syncing ***** beyond belief since the recent Iphone update - PLS APL FIX!!!

    I did a search on this forum for can't sync and got over 500 results. NONE of which has fixed my problem, and many many others are having the same problems. And no, my phone has not been hacked, altered, dropped or anything else. It all started the d