US and Worldwide: +1 (866) 660-7555
Results 1 to 6 of 6

Thread: multiple lines in one of the columns of JTable.

  1. #1
    Join Date
    Mar 2003
    Posts
    4,947

    Default multiple lines in one of the columns of JTable.

    i have one of my table column which has long text which could be having multiple lines.
    I have written the following lines in TableModel class.
    Code:
      
    
      public Object getValueAt (int row, int column)
      {
          if(column == 2)
          {
              String str = (String)data[row][column];
              if (str.length()>50)
              {
                  String html_string = "<html>" + str.substring&#40;0,50&#41; + "
    " + str.substring&#40;50,str.length&#41;;
              &#125;
          &#125;
        return data&#91;row&#93;&#91;column&#93;;
      &#125;
    By doing so in the JTable i can see multiple lines for all the text greateg then 50, but in the report i'm getting html tags also and all in the same line.
    can any one give me ome better idea then this.

    TIA

  2. #2
    Join Date
    Mar 2003
    Posts
    7,956

    Default

    Hi,

    the JTable uses a JLabel (and javax.swing.text.Document) to parse and format the HTML content. JFreeReport does not perform this (really expensive) operation, we expect PlainText. If you want to insert line breaks, then just insert the character '\n' into your text.

    But just because the text may be too long, you don't have to insert line breaks. Just define your text element to be dynamic (or increase the text element's height to "numberOfLines * fontSize") and let JFreeReport do all the linebreaking. JFreeReport will break the text on word boundries automaticly.

    Have more fun,
    said Thomas

  3. #3
    Join Date
    Mar 2003
    Posts
    4,947

    Default another help

    Ya i tried that,
    i have one one column with long text and teh secon column is a date.
    so i just wanted my first coloumn to be line wrapped,

    i iam having my report filed something like this.
    Code:
    <items height="20" fontname="Monospaced" fontstyle="plain" fontsize="8">
        
        <string-field x="0" y="0" width="300" height="8" alignment="left" fieldname="File"/>
        <string-field x="300" y="0" width="60" height="8" alignment="left" fieldname="Date Created"/>
        <string-field x="360" y="0" width="60" height="8" alignment="left" fieldname="Date Modified"/>
        <number-field x="420" y="0" width="60" height="8" alignment="right" format="#,##0" fieldname="Size"/>
        
      </items>
    i wanted my field name File to be dynamic how can i do that.
    TIA

  4. #4
    Join Date
    Mar 2003
    Posts
    7,956

    Default

    Hi,

    simple, just add the attribute dynamic="true" to your element:

    <string-field x="0" y="0" width="300" height="8" alignment="left" fieldname="File" dynamic="true"/>

    Have more fun,
    said Thomas

  5. #5
    Join Date
    Mar 2003
    Posts
    4,947

    Default Thanx that worked great

    It worked fin i'm getting multiple lines,
    Now i have anothr problem by which i can bother you further..

    I am getting mulitiple lines but those filed which are not that big are usiing
    the extra space.
    id there any way to stop that.
    what i mean to say is
    columns with large line using height coresponding to this length is fine.
    but columns ith small lines also are now using multiple lines
    how can i stop that.
    TIA

  6. #6
    Join Date
    Mar 2003
    Posts
    7,956

    Default

    Hi,

    the itemband's height is defined by the height of the largest column. Once the complete itemband is printed, the reporting advances to the next position.

    The itemband is an element container an behaves similiar to an AWT container. Your report will always look like this:

    Code:
    -------------------------------------------------------------------
    row1       a column with some text      a column with much more
                                            text, so that a linebreak
                                            is done here. The height
                                            of this column will define
                                            used height of the item-
                                            band.
    -------------------------------------------------------------------
    row2       another column               this is the next itemband,
                                            there is no other way of 
                                            printing.
    Have more fun,
    said Thomas

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •