How to delete the logical lines in JTextArea

Hi all,
Now that I know how to find the logical line count in JTextArea as
I found the following in the forum.
public static int getLineCount (JTextArea _textArea)
boolean lineWrapHolder = _textArea.getLineWrap();
_textArea.setLineWrap(false);
double height = _textArea.getPreferredSize().getHeight();
_textArea.setLineWrap(lineWrapHolder);
double rowSize = height/_textArea.getLineCount();
return (int) (_textArea.getPreferredSize().getHeight() / rowSize);
I want to delete the 4th line to the last line and append ... at the 4th, if the getLineCount exceeds 3. Does any body know how to do so?
The intention is for the multiline tooltip as I just want to show
the first three logical line and ... if the string is too long.
Thanks
Pin

The code looks good to me. The only thought I have is that the y coordinate for the rowThree point is wrong and is referencing row four.
I've been playing around with using a JTextArea as a renderer for a JTable. I have it working so that "..." appear when the text exceeds 2 rows. Try clicking on "B" in the letter column and then the update cell button a few times to add text. My code is slightly different than yours.
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
public class TestTable extends JFrame
     private final static String LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
     JTable table;
     Vector row;
     public TestTable()
          Object[][] data = { {"1", "A"}, {"2", "B"}, {"3", "C"} };
          String[] columnNames = {"Number","Letter"};
          DefaultTableModel model = new DefaultTableModel(data, columnNames);
          table = new JTable(model)
               public String getToolTipText( MouseEvent e )
                    int row = rowAtPoint( e.getPoint() );
                    int column = columnAtPoint( e.getPoint() );
                    if (row == 0)
                         return null;
                    else
                         return row + " : " + column;
          table.setRowSelectionInterval(0, 0);
          table.setColumnSelectionInterval(0, 0);
          table.setRowHeight(0,34);
          table.setRowHeight(1,34);
          table.setRowHeight(2,34);
          table.setDefaultRenderer(Object.class, new TextAreaRenderer(2));
          JScrollPane scrollPane = new JScrollPane( table );
          getContentPane().add( scrollPane );
          JPanel buttonPanel = new JPanel();
          getContentPane().add( buttonPanel, BorderLayout.SOUTH );
          JButton button2 = new JButton( "Update Cell" );
          buttonPanel.add( button2 );
          button2.addActionListener( new ActionListener()
               public void actionPerformed(ActionEvent e)
                    int row = table.getSelectedRow();
                    int column = table.getSelectedColumn();
                    String value = (String)table.getValueAt(row, column);
                    value += value;
                    table.setValueAt( value, row, column );
                    DefaultTableModel model = (DefaultTableModel)table.getModel();
                    model.fireTableCellUpdated(row, column);
                    table.requestFocus();
     public static void main(String[] args)
          TestTable frame = new TestTable();
          frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
          frame.pack();
          frame.setVisible(true);
     private class TextAreaRenderer extends JTextArea implements TableCellRenderer
          public TextAreaRenderer(int displayRows)
               setRows(displayRows);
               setLineWrap( true );
          public Component getTableCellRendererComponent(JTable table,
                                         Object value,
                                         boolean isSelected,
                                         boolean hasFocus,
                                         int row,
                                         int column)
               setText( value.toString() );
               Dimension d = getPreferredSize();
               int maximumHeight = getRows() * getRowHeight();
               if (d.height > maximumHeight)
                    setSize(d);
                    int offset = viewToModel( new Point(d.width, maximumHeight - 1) );
                    replaceRange( "...", offset-3, getDocument().getLength() );
               return this;
}

Similar Messages

  • How to delete the specified line in file?

    How to delete the specified line in file? In case of deleting a specified line in a file, how to do?
    Line 1
    Line 2
    Line 3
    Line 4
    Line 5
    The case is a file including the above content. Now I wanna to delete the "Line 3" and how to realize the action in Java?

    An alternative solution can be :
    import java.io.LineNumberReader;
    import java.io.IOException;
    import java.io.File;
    import java.io.FileReader;
    import java.io.BufferedWriter;
    import java.io.FileWriter;
    import java.io.PrintWriter;
    public class LineDeleter {
    public static void main(String args[]){
    try {
    //suppose you want to delete line 3
         int lineToBeDeleted = 3;
         File f = new File("line.txt");
         long fileSize = f.length();
    //Wrap the FileReader with a LineNumberReader. It will help you
    //identify the lines.
    LineNumberReader lnr = new LineNumberReader( new FileReader(f));
    //Wrap the FileWriter object with BufferedWriter object. Create it with the buffersize
    //equal to the file size.
         BufferedWriter bw = new BufferedWriter(new FileWriter(new File("line1.txt")),(int)fileSize);
    //Wrap BufferedWriter object with PrintWriter so that it allows you
    //to print line by line
    PrintWriter pw = new PrintWriter(bw);
         String s=null;
         while ( (s=lnr.readLine())!=null ){
              System.out.println(s);
              int lineNumber = lnr.getLineNumber();
    //match the line number
              if(! (lineNumber==lineToBeDeleted)){
                   pw.println(s);
              pw.flush();
              lnr.close();
              pw.close();
         catch(Exception e){System.out.println(e);}
    If you want you can rename the line1.txt to the original file name.
    I hope this helps.Good luck!!!!!!

  • How to delete the horiz line of addresses beneath the address bar

    How to delete the horiz line of addresses beneath the address window. They are not affected by the "delete recent sites" tool.

    Do you mean the tab bar?
    See [[Tabbed browsing]]

  • How To delete the Chosen line from the Table Control

    Hi Friends,
      i am new to Module Pool Programming , i developed a Table Control in input mode and i am getting data also into that table control. my requirement is that i want to delete the current chosen line from that table control. please help me out.

    HI
    GOOD
    GO THROUGH THIS REPORT
    REPORT demo_dynpro_tabcont_loop_at.
    CONTROLS flights TYPE TABLEVIEW USING SCREEN 100.
    DATA: cols LIKE LINE OF flights-cols,
    lines TYPE i.
    DATA: ok_code TYPE sy-ucomm,
          save_ok TYPE sy-ucomm.
    DATA: itab TYPE TABLE OF demo_conn.
          TABLES demo_conn.
    SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE itab.
    LOOP AT flights-cols INTO cols WHERE index GT 2.
      cols-screen-input = '0'.
      MODIFY flights-cols FROM cols INDEX sy-tabix.
    ENDLOOP.
    CALL SCREEN 100.
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'SCREEN_100'.
    DESCRIBE TABLE itab LINES lines.
    flights-lines = lines.
    ENDMODULE.
    MODULE cancel INPUT.
      LEAVE PROGRAM.
    ENDMODULE.
    MODULE read_table_control INPUT.
      MODIFY itab FROM demo_conn INDEX flights-current_line.
    ENDMODULE.
    MODULE user_command_0100 INPUT.
      save_ok = ok_code.
      CLEAR ok_code.
      CASE save_ok.
        WHEN 'TOGGLE'.
          LOOP AT flights-cols INTO cols WHERE index GT 2.
            IF  cols-screen-input = '0'.
              cols-screen-input = '1'.
            ELSEIF  cols-screen-input = '1'.
              cols-screen-input = '0'.
          ENDIF.
      MODIFY flights-cols FROM cols INDEX sy-tabix.
    ENDLOOP.
        WHEN 'SORT_UP'.
          READ TABLE flights-cols INTO cols WITH KEY selected = 'X'.
          IF sy-subrc = 0.
            SORT itab STABLE BY (cols-screen-name+10) ASCENDING.
            cols-selected = ' '.
      MODIFY flights-cols FROM cols INDEX sy-tabix.
          ENDIF.
        WHEN 'SORT_DOWN'.
          READ TABLE flights-cols INTO cols WITH KEY selected = 'X'.
          IF sy-subrc = 0.
            SORT itab STABLE BY (cols-screen-name+10) DESCENDING.
            cols-selected = ' '.
      MODIFY flights-cols FROM cols INDEX sy-tabix.
          ENDIF.
        WHEN 'DELETE'.
          READ TABLE flights-cols INTO cols
                                  WITH KEY screen-input = '1'.
          IF sy-subrc = 0.
            LOOP AT itab INTO demo_conn WHERE mark = 'X'.
              DELETE itab.
    ENDLOOP.
          ENDIF.
    ENDCASE.
    ENDMODULE.
    CHANGE THE CODE AS PER THIS LIGIC.
    THANKS
    MRUTYUN

  • To delete the last line of the internal table

    How to delete the last line of the internal table.???????
    The list which gets displayed from the internal table adds a dummy line at the last which shows zeros and zeros.all the otheer selections are perfect.i just want to delete the last line which comes as zero zero.is there any way to do it...

    Quite Easy......Use Describe command to Count the Total Number of Table Lines, and then Delete the Last Line using Index.
    Data L like sy-tabix.
    Describe Table Itab Lines L.
    Delete itab index L.

  • How to delete the Cost center line item data

    How to delete the cost center line item data of particular cost center and only one cost center is exisiting for that company code.
    Is there any way to delete the line items in that cost center.
    Can data archiving & deleting can help us..........
    does it have any effect over other cost center data....
    any input needed.........
    regards
    rajesh

    Hi,
    i found 2 reports for you:
    1) CO_TOTAL_WRI - Archiving CO Totals Records   
    2) RKCOITW1     - Archiving CO Line Items: Write Program        
    from 2) is a linlk to customize archiv-parameters
    -> start it with transaction se38 / sa38
    A.

  • How to delete the old schedule line release?

    Hello,
    How to delete the old schedule line release in apo?
    Generally GR has to be carry out  schedule line release  in r/3 which reduces the Schdule line release.
    But i do want do GR against old schdule line release instead i want to delete the old schdule line release.
    Please suggest.
    Regards,
    Sunil Patil

    Sunil ,
    /sapapo/cmds_del  is the tcode to deleted sales scheduling agreement confirmations and releases
    /sapapo/display_conf  is the tcode for displaying sls. sch.agr confirmations and releases
    The above two are in the supply chain collaboration menu
    /sappao/cmds_sc02 is the tcode to delete sales scheduling agreements . This tcode is in the application specific master data menu
    Thanks
    Saradha

  • How to delete the old schedule line release in apo

    How to delete the old schedule line release (from current date) in apo which is having schedule  firmed?
    Please suugest.
    Sunil

    How is it possible to delete old purchasing schedule lines in APO (that do not exist in R/3)?
    Though used successfully before, /SAPAPO/CCR will not reconcile our discrepancy in this case.
    Thanks in advance,
    Jim

  • I get a message Debug Error:[Exception... "Node was not found" code: "8" nsresult: "0x80530008 (NS_ERROR_DOM_NOT_FOUND_ERR)" location: "chrome://ffebayhot/content/lib/Extension.debug.js Line: 366"] using Vista. I don't understand how to delete the "ebay

    Every time I try to use google for a search, I get the following error msg. Debug Error:[Exception... "Node was not found" code: "8" nsresult: "0x80530008 (NS_ERROR_DOM_NOT_FOUND_ERR)" location: "chrome://ffebayhot/content/lib/Extension.debug.js Line: 366"]. I saw the solution provided for MS XP, but not for Vista. Also, while I saw the solution, I need more explicit instructions on how to "delete the ebay extension".
    == This happened ==
    Every time Firefox opened
    == When I try to load google from Firefox, I get the error message, Debug Error:[Exception... "Node was not found" code: "8" nsresult: "0x80530008 (NS_ERROR_DOM_NOT_FOUND_ERR)" location: "chrome://ffebayhot/content/lib/Extension.debug.js Line: 366"]

    Tools->Add-ons->Extensions
    At the top of the Firefox window, click on the Tools menu and select Add-ons. The Add-ons window will appear.
    In the Add-ons window, select the Extensions panel.
    Select the add-on you wish to uninstall.
    Click the Uninstall button. When prompted, click Uninstall to confirm.
    Then restart Firefox.
    Read here:
    [[Uninstalling add-ons|#How to uninstall extensions and themes|Uninstalling extensions]]

  • How to delete the line between the last point and first point?

    How to delete the line between the last point and first point? 
    I want to draw a curve many times, from first point to the end point. and redraw from first point to the end point.But I hope update point by point. but between the end point and the first point,  there is a line. How to delete the line?
    the code is:
    CNiReal64Vector plotData(50);
    m_graph.ChartLength = 50;
    //m_graph.ClearData();
    for (int j = 0; j < 2; j++)
           for (int i=0; i<50; i++)
                   plotData[i] = ((double)rand()/(double)RAND_MAX)*6 + 4;
                   m_graph.GetPlots().Item("Plot-1").ChartXY(i, plotData[i]);
                   Sleep(100);
    Attachments:
    20150605142608.png ‏31 KB

    Hi Kumar,
    I think you can just delete it in the sales order directly, if you are using make-to-order scenario, then there will be special stock left for the sales order as the production has been goods receipt, you need to use MM transaction move the stock to unrestricted use stock. If you are using make-to-stock scenario, there should be no further problem. If you are using assembly order, please try to reject the sales order item to see if it could fullfill your requirement.
    Regards,
    Rachel

  • How to delete string or line from unix file(dataset) of application server

    Hi  All,
    After transfer workarea information or all records into dataset(unix file). When I see the file in application server automatically the last line is shown a blank line. I am not passing any blank line.
    I have tried for single record than also the file generates the last line(2nd line) also a blank line.
    When I m reading the dataset, it is not reading the last blank line but why it is showing the last blank line?
    How to delete string or line from unix file(dataset) of application server?
    Please give your comments to resolve this.
    Thanks
    Tirumula Rao Chinni

    Hi Rio,
    I faced similar kind of issue working with files on UNIX platform.
    The line is a line feed to remove it use
    DATA : lv_carr_linefd TYPE abap_cr_lf VALUE cl_abap_char_utilities=>cr_lf. 
      DATA : lv_carr_return TYPE char1,                                   
             lv_line_feed   TYPE char1.                                          
      lv_line_feed   = lv_carr_linefd(1).
      lv_carr_return = lv_carr_linefd+1(1).
    Note: IMP: The character in ' ' is not space but is a special
    character set by pressing ALT and +255 simultaneosly
      REPLACE ALL OCCURRENCES OF lv_line_feed IN l_string WITH ' '.
      REPLACE ALL OCCURRENCES OF lv_carr_return IN l_string WITH ' '.

  • How to delete the data from partition table

    Hi all,
    Am very new to partition concepts in oracle..
    here my question is how to delete the data from partition table.
    is the below query will work ?
    delete from table1 partition (P_2008_1212)
    we have define range partition ...
    or help me how to delete the data from partition table.
    Thanks
    Sree

    874823 wrote:
    delete from table1 partition (P_2008_1212)This approach is wrong - as Andre pointed, this is not how partition tables should be used.
    Oracle supports different structures for data and indexes. A table can be a hash table or index organised table. It can have B+tree index. It can have bitmap indexes. It can be partitioned. Etc.
    How the table implements its structure is a physical design consideration.
    Application code should only deal with the logical data structure. How that data structure is physically implemented has no bearing on application. Does your application need to know what the indexes are and the names of the indexes,in order to use a table? Obviously not. So why then does your application need to know that the table is partitioned?
    When your application code starts referring directly to physical partitions, it needs to know HOW the table is partitioned. It needs to know WHAT partitions to use. It needs to know the names of the partitions. Etc.
    And why? All this means is increased complexity in application code as this code now needs to know and understand the physical data structure. This app code is now more complex, has more moving parts, will have more bugs, and will be more complex to maintain.
    Oracle can take an app SQL and it can determine (based on the predicates of the SQL), which partitions to use and not use for executing that SQL. All done totally transparently. The app does not need to know that the table is even partitioned.
    This is a crucial concept to understand and get right.

  • How to delete the duplicate data  from PSA Table

    Dear All,
    How to delete the duplicate data  from PSA Table, I have the purchase cube and I am getting the data from Item data source.
    In PSA table, I found the some cancellation records for that particular records quantity  would be negative for the same record value would be positive.
    Due to this reason the quantity is updated to target but the values would summarized and got  the summarized value  of all normal and cancellation .
    Please let me know the solution how to delete the data while updating to the target.
    Thanks
    Regards,
    Sai

    Hi,
    in deleting the records in PSA table difficult and how many you will the delete.
    you can achieve the different ways.
    1. creating the DSO maintain the some key fields it will overwrite the based on key fields.
    2. you can write the ABAP logic deleting the duplicate records at info package level check with the your ABAPer.
    3.you can restrict the cancellation records at query level.
    Thanks,
    Phani.

  • IMP: How to delete the service order

    Hey Experts,
    Can you tell me how to delete the service order which was created in IW31..? or we have any Functions Module to delete the service order?
    and one more question is I have more than 100 service order in the table ,but it will display only 50 order when i execute this Functions Module BAPI_ALM_ORDERHEAD_GET_LIST
    can you tell me how to solve this problem...?
    Thanking you in advance,
    Regards
    J Sarathi

    This is what the BAPI_ALM_ORDERHEAD_GET_LIST documentation says
    "You can use this method to determine a list of orders according to a list of selection criteria. The number of hits that are produced for the person calling up the list, can be specifically reduced; without further parameter transfers, the first 50 hits are displayed. A complete list of the hits is stored internally. If you call up the selection again within a Logical Unit of Work (LUW) without changing the selection parameters, but with other refurbishment parameters, then you receive further partial quantities of the selection result, as specified by you."
    and for deletion
    check whether you can set any deletion status through the fm BAPI_ALM_ORDER_MAINTAIN
    Also check the business objects BUS2007, BUS2088

  • How to delete a whole line in cmd prompt in Linux

    Hi all,
    How to delete a whole line in cmd prompt in Linux using short key?
    ex: [oracle@host1 ~]$ cd /u01/app/oracle/product/11.2.0/dbhome_1/
    Thanks

    yes ctrl+ak or ctrl+eu both are better. if you look from that perspective, go end and delete will be the same job too. (ctrl+eu) (but for me in such a command line, for example cding in to the directories ,the cursor will be at the end of the line %99 of the time :) )
    about ctrl-t,
    Drag the character before the cursor forward over the character at the cursor, moving the cursor forward as well. If the insertion point is at the end of the line, then this transposes the last two characters of the line.
    for ex:
    misspelled command date -> daet -> ctrl+t -> date
    or
    misspelled command $APPPL_TO -> place the cursor on third P press ctrl+t repeateadly till the P will come to the end -> APPL_TOP

Maybe you are looking for