Multiple Line cell render in  JTable

The issue here is that what's the right way to judge
how many lines is needed to show the Object value in TableCellRender's
public Component getTableCellRendererComponent(
JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column)
The way by FontMetrics or by Component's getPreferredSize() is not correct.
For a short Object value = "FAC Question" for which the table column is wide enough to display whole string,
the width by calculating FontMetrice on this Object could be larger than the width of table column.
For example:
Object value = "FAC Question A";
tableColumn.getPreferredSize().width = 75;
fontMetrics.stringWidth(value)=120;
getTableCellRenderComponent(...).getPreferredSize().width=120

Hi, use
JTable table = new JTable();
DefaultListSelectionModel  dlm =  new DefaultListSelectionModel();
dlm.setSelectionMode( ListSelectionModel.MULTIPLE_INTERVAL_SELECTION  ); //1( the first one should be the one you are looking for)
or (choose 1 or 2, the rest stays the same)
dlm.setSelectionMode( ListSelectionModel.SINGLE_INTERVAL_SELECTION );//2
table.getColumnModel().setSelectionModel(dlm);
table.setCellSelectionEnabled(true);Hope this helps.
Greetings Michael.

Similar Messages

  • Append table with multi-line cells to word report

    Hi,
    I am using LabView 7.0. I need to append table to word report and I am using Append Table to Report VI. My VI works fine as long as the table cells do not have multiple lines. For multiple lines, each line is put is a seperate cell in the word report.
    Is there a way to append multi-line cells to Word Report??? If not, any suggestions on how I can copy the multi-line table to Word report???
    Please kindly help!!
    Please see the attached document for details on the problem.
    Thanks,
    Mim
    Attachments:
    Table with multiple line cells.doc ‏33 KB

    Hi Mim,
    Yes I understood the multiple-lines part. I think the doc is the report you want. Correct ?
    The doc is generated with your VI without any modifications.
    I am using XP, Office 2002 SP3 and LV7.1
    Attachments:
    Verification Report.doc ‏39 KB

  • Multiple Lines in a Jtable Cell

    I am trying to place multiple lines in a single cell of Jtable
    The text Of the cell comes from the database.I am trying to do it using a JLabel .If anyone can help me please do so
    thanks
    kishore
    [email protected]

    It can be done but it is quite a lot of work. Basically you have to produce your own cell renderer and use that instead. A good book on swing will tell you how to do it.

  • Table Cell Editor which allows to input multiple lines of text...

    Hi there
    Does anyone know how to write a table cell editor which allows users to input multiple lines of text? please provide some sample if possible...
    Thanks
    Ken

    I'm assuming you also want the renderer to display multiple lines? if so, make a class that extends JTextArea and that implements the TableCellEditor and TableCellRenderer interfaces, then set instances of this as the editor and renderer for the TableColumn in question. The implementation of most of the methods in these interfaces is trivial, often just this.setBackground() based on the table.getSelectionBackground() or table.getBackground(), a this.setText() based on the value passed in, then just a 'return this'.
    You might want to make an abstract class which implements these interfaces for you, and which delegates to a simple abstract method that you override to return the renderer/editor component.
    Note that you must use two instances of the class you make, one for the renderer and one for the editor, since it must be able to be able to render the remainder of the table's cells without interfering with the JTextArea performing the editing. (alternatively you could make two classes that extend JTextArea, each just implementing one of the interfaces, but this is more effort I think.) Also note that you must increase the table's row height to get more than one row visible.

  • How do i add multiple lines in a cell (like a list) in Excel for MAC?

    I'm trying to add multiple lines (in the form of a list) in a individual cell in Excel for MAC.  I used ALT Enter on my PC but that doesn't work on the iMac.  Does anyone know how to do this?
    Thanks!

    It's been a while but I think you hold SHIFT while typing a page break (RETURN) to make a new line without shifting to another cell.
    However, as Excel isn't an Apple product, I am sure you will get a faster and more current answer by using Microsoft's Office:Mac forums here:
    Office for Mac forums
    They are very good.

  • Multiple Lines in a Single ALV Grid Cell

    Is there any way to Display Multiple Lines in a Single ALV Grid Cell.
    This can be accomplished by Sorting the First 3 fields and Make it Looks like below displayed format.
    But My problem is while downloading also it should be Displayed in the same format.
    All inputs are highly appreciated.

    there was a post similar to this some days back... search it..
    any ways...
    what u can do is...
    arrange ur final internal table so that it will look like same line...
    like...lets say ur internal table is :
    A1 B1 C1 D1 123
    A1 B1 C2 D2 123
    A1 B2 C1 D1 123
    A1 B2 C2 D2 123
    and u can rearrange ur table to be like
    A1 B1 C1 D1 123
          C2 D2 123
    A1 B2 C1 D1 123
          C2 D2 123
    what i mean to say is dont pass the fields if they are same in the previous line... try it out..
    and then pass it two ur ALV.
    it will look like they are in one line
    Edited by: soumya prakash mishra on Jun 17, 2009 1:31 PM

  • How do I add multiple lines to a cell

    I am trying to create an assignment sheet in Numbers. I am using the "Schedule" template. Under each day of the week, I want to add daily assignments. But each assignment may need multiple lines. In the screenshot below, I want to add another line under "Genesis 5" but still have it within the same cell. How can I do that?

    I do extensive research  build on the work of others

  • Multiple lines in a cell in excel download

    Hi,
    I have used insert_full of i_oi_spreadsheet interface for downloading internal table.. i have a text field which i need to display in multiple lines in one cell.
    Is that possible? Please help,
    Regards,
    Rohit.

    Rohit,
    Clipboard this code into your editor and see if it helps you out.  Please reward points.
    *& Report  ZR_SANDBOX_PROG
    REPORT Zsandbox_prog .
    INCLUDE OLE2INCL.
    DATA: hExcel TYPE OLE2_OBJECT,      " Excel object
          hWorkBooks TYPE OLE2_OBJECT,  " list of workbooks
          hWorkbook TYPE OLE2_OBJECT,   " workbook
          hSheet TYPE OLE2_OBJECT,      " worksheet object
          hRange TYPE OLE2_OBJECT,      " range object
          hRange2 TYPE OLE2_OBJECT,      " range object
          hBorders TYPE OLE2_OBJECT,    " Border object
          hInterior TYPE OLE2_OBJECT,   " interior object - for coloring
          hColumn TYPE OLE2_OBJECT,     "column
          hCell TYPE OLE2_OBJECT,       " cell
          hFont TYPE OLE2_OBJECT,       " font
          hSelected TYPE OLE2_OBJECT,   " range object
          hPicture TYPE OLE2_OBJECT,    "picture object
          hLogo TYPE OLE2_OBJECT.       "Logo object
    types:  begin of t_Excel,
              Period_Literal(20),
              Pd_Wk_Literal(20),
              Coop_Literal(40),
              Sugg_Price(20),
              Cost(20),
              Margin(20),
              Comments(100),
            end of t_Excel.
    data: r_Excel type t_Excel.
    data: i_Excel type table of t_Excel with header line.
    field-symbols: <Val> type any.
    data: col_Cnt type i.
    data: row_Cnt type i.
    data: l_range(30).
      parameters: wraptext as checkbox.
      CREATE OBJECT hExcel 'EXCEL.APPLICATION'.
      PERFORM ERR_HDL.
    get list of workbooks, initially empty
      CALL METHOD OF hExcel 'Workbooks' = hWorkbooks.
      PERFORM ERR_HDL.
    add a new workbook
      CALL METHOD OF hWorkbooks 'Add' = hWorkbook.
      PERFORM ERR_HDL.
    Get Worksheet object.
      get property of hWorkbook 'ActiveSheet' = hSheet.
      SET PROPERTY OF hExcel  'Visible' = 1.
      row_cnt = 1.  col_cnt = 1.
      do 5 times.
        Perform Load_Dummy_Values.
      enddo.
    *Pass the internal table values to the spreadsheet.
      loop at i_Excel into r_Excel.
        do 7 times.
          assign component sy-index of STRUCTURE r_excel TO <Val>.
          PERFORM Fill_The_Cell USING row_cnt col_cnt 0 <Val>.
          col_cnt = col_cnt + 1.      "increment column
        enddo.
        row_cnt =   row_cnt + 1.    "increment row
        col_cnt = 1.                  "reset column to A (ie. col 1)
      endloop.
      if not WrapText is initial.
        move 'G:G' to l_range.
        CALL METHOD OF hExcel 'RANGE' = hRange EXPORTING #1 = l_range.
        set property of hRange 'WrapText' = 1.
      endif.
    Release excel.
      FREE OBJECT hExcel.
      PERFORM ERR_HDL.
    FORM Fill_The_Cell USING I J BOLD TheValue.
      CALL METHOD OF hExcel 'Cells' = hCell EXPORTING #1 = I #2 = J.
      PERFORM ERR_HDL.
      SET PROPERTY OF hCell 'Value' = TheValue.
      PERFORM ERR_HDL.
      GET PROPERTY OF hCell 'Font' = hFont.
      PERFORM ERR_HDL.
      SET PROPERTY OF hFont 'Bold' = BOLD.
      PERFORM ERR_HDL.
    ENDFORM.
    *&      Form  ERR_HDL
          outputs OLE error if any
    -->  p1        text
    <--  p2        text
    FORM ERR_HDL.
      IF SY-SUBRC <> 0.
        message i000(zz) with 'OLE Automation error: ' SY-SUBRC.
        exit.
      ENDIF.
    ENDFORM.                    " ERR_HDL
    Form Load_Dummy_Values.
      r_excel-Period_Literal = 'Period 1'.
      r_excel-Pd_Wk_Literal = 'P1 / Wk1'.
      r_excel-Coop_Literal = 'Promo Event'.
      r_excel-Sugg_Price = '$ 1.25'.
      r_excel-Cost  = '$ 0.50'.
      r_excel-Comments =
       'This is a really long field with one hundred bytes to it.'.
      append r_excel to i_Excel.
    EndForm.

  • JTable cell render problem, help!

    Hi all,
    I'm trying to change the color of some cells in a JTable. I have the definition of what cell to render in a different color in a Vector. So each time the cell render is called, I check if the cell it's in my vector, and if yes I change the background color to red.
    The problem is, the result are not the desired, some cells are some times in red other times in red! Some one have an idea of what appends?
    Thanks NeuralC
    public Component getTableCellRendererComponentJTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    Component cell = super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column);
    for(int i=0;i<((LinhaRefresh)RefreshOjb.elementAt(row)).Gamas.size();i++){
    if(((column)>=((Gama)((LinhaRefresh)RefreshOjb.elementAt(row)).Gamas.elementAt(i)).inicio) & ((column) <=((Gama)((LinhaRefresh)RefreshOjb.elementAt(row)).Gamas.elementAt(i)).fim)){
    cell.setBackground(Color.red);
    return cell;
    cell.setBackground(Color.white);
    return cell;
    }

    Hi,
    AND symbol is &, and I must use it.
    I haved solved the problem, extending my cell render to a JLabel. With this and making my self the selection color everything works fine.
    Thanks for interrest.
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    JLabel lb = new JLabel((String)value);
    //Component cell = super..;
    setText((String)value);
    if(!isSelected){
    setBackground(Color.white);
    else{
    setBackground(Color.blue);
    for(int i=0;i<((LinhaRefresh)RefreshOjb.elementAt(row)).Gamas.size();i++){
    if(((column)>=((Gama)((LinhaRefresh)RefreshOjb.elementAt(row)).Gamas.elementAt(i)).inicio) & ((column) <=((Gama)((LinhaRefresh)RefreshOjb.elementAt(row)).Gamas.elementAt(i)).fim)){
    if(hasFocus){
    setToolTipText("est� dentro"+column);
    setBackground(Color.red);
    return this;

  • Jtable: can a row have multiple lines

    Hello all,
    Can a Jtable row have multiple lines? For instance, if the string is too long, can i set a property so that the line breaks and makes the row larger (vertically), rather than carrying off the table (horizontally)? If so, can you please point me in the direction of what property to edit.
    Thanks in advance!

    You should be able to write a renderer using a JTextArea and set it on that column. that should atleast give you a start to wrap the text. But you need to add it to the scroll pane etc etc.
    but i think you need to do more to increase the size of the row vertically.
    Hope this gives you a start
    -nicedude

  • How to render multiple lines of text?

    Hi,
    I have a string variable in a backing bean,which holds multiple lines of text with newline character as the seperator.
    I have to display it in my jspx page.
    Which component is suggestable?
    Thanks,
    Lokesh.

    Hi Lokesh,
    Try the <tr:outputDocument/> component, it does just that, splitting each lines as paragraph elements.
    Regards,
    ~ Simon
    Edited by: Simon Lessard on Jan 28, 2009 1:44 PM

  • Multiple Lines Header and Records in ALV List

    Dear All,
    I am faced with a wierd user requirement to print multiple line header in ALV. Currently we have a classical report where we are displaying a huge text for example 400 characters in a single cell of a column of the report.
    Now we will have to convert this to ALV report where I need to show that data in a single cell. I am wondering how is it possible in ALV list/grid. Please let me know if you guys have any clue.
    Regards,
    Bikramjit

    Hi,
    Did you find a solution for this?, I am also having a similar requirement.
    If you have any work around please share.
    Thanks.

  • Creating SVG Chart with multiple lines

    Hi All,
    I want to create a chart with multiple lines.
    Ex: I have one emp table with empno, sal and deptno columns.
    I want to print deptno in x axis and no of employees on y axis.
    I want to print one line for employees with sal > 15000 and one more line for employee with sal =< 15000
    So one line will show no of employees with sal more than 15000 for each dept. Similar case for the other line and these 2 lines should be in different colors.
    For one line the query will go as
    select link, deptno, count(empno)
    from emp where sal > 15000 group by null, deptno
    Is this possible to draw this chart?
    Thanks,
    Manoj

    I wasn't able to do something like what you describe, but I was able to do this:
    I defined column A of the table as a Header Row, selected the cells in the table, and chose this chart type (2D 2 Axis):
    Then I clicked the chart and in the pane at the right checked 'Axis Name' in the Axis tab and added the axis names.
    Maybe this can give you an idea of how you can illustrate the relationships that you want to show.
    SG

  • How can I produce a title card with multiple lines of text?

    When I drag "title, multiple lines" to my timeline, the second line appears in a smaller font. When I type all my text on a single line, the title appears in a teeny-tiny font. I want to be able to produce four or five lines of text, all in a readable font. Help!

    2 solutions:
    Costs money and takes work:
    Look for a title plug-in on geethree.com. There are free ones out there too.
    OR.
    Works right now:
    Type your title into the 'scrolling block' title.
    Drop it in and let it render.
    Play it back and pause it when the text is in the middle (or where ever you want it). Choose 'create still clip' from the edit menu. And blamo! You've got multiple lines of the same sized text.
    This might take some experimenting to find what font works best. Some get a little jaggy in the rendering process and look bit-mapped a bit when changed into a still.
    Give it a shot!

  • Text Fields of an External Content Type come across as Multiple Line of Text

    In SharePoint 2013 I have an external content type that consists of a couple of short (nvarchar)  fields (no more that 15 characters). When I use this ECT in a custom list the fields from the ECT end up as a "Note" type instead of "Text".
    I am not sure how this happens. I have verified this by accessing the list via poweshell where I see the Type being as "Note" and also the SchemaXml showing the colName attribute as "ntext".
    The strange thing is that initially when I created the web application and built my lists this was working.
    Any ideas or pointers would be appreciated.
    Thanks

    Hi,
    Based on your description, my understanding is that When you use the ECT in a custom list the fields from the ECT end up as a "Note" type instead of "Text".
    Have you ever changed column types from "Single line of text" to "Multiple Lines of Text" in list?http://www.sharepointdiary.com/2013/09/change-column-type-in-list-using-powershell.html
    External content types are made up of fields whose types are a subset of the primitive types of .NET. For each such .NET type, a rudimentary mapping to SharePoint’s field controls exists, describing a field’s visual appearance. Fields of type string for
    instance will, on the new and edit forms, render as a single-line text field.
    Besides, check whether the following link is useful:
    https://social.technet.microsoft.com/Forums/sharepoint/en-US/0fcb5a9f-8445-4a37-9e60-ac5e9e14e8f1/sharepoint-designer-external-content-type-shows-single-line-text?forum=sharepointgeneralprevious
    Best Regards,
    Lisa Chen
    Forum Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help. If you have feedback for TechNet Subscriber Support, contact
    [email protected]
    Lisa Chen
    TechNet Community Support

Maybe you are looking for

  • Is itunes compatible with windows 8

    Is itunes compatible with windows 8. I get 100% disk usage when downloading from itunes store.

  • Help - upgrade from OS 8.6 to OS 10.3.9

    I am trying to breathe life into our slot loading G3iMac. It currently runs OS 8.6 I know I need to update the firmware but it says it needs OS 9.1 to upgrade firmware. Do I need to purchase and install OS 9 or can I simply upgrade the firmware and i

  • Acc tag - iTunes Library unsynced

    Hi, I have this very strange problem: when I try to change some data in some files through the iTunes (i.e. the "artist" field) I see it change in iTunes, but first time I play it it came right back to the wrong one. It happens also by telling iTunes

  • DVD Writer not working.

    I using Windows XPSP2 Professonal. My DVD Writer Read any CD/DVD but it cant write. I write that DV D/CD in other PC, Which DVD/CD are not write in my PC. I have one year warranty, 5 Month left.

  • Third party synth problem.

    Hi Folks: I am a Blind user of GarageBand on a MacBook Pro using Voiceover and I have installed both the Ivory 2 piano and the TruePianos software programs. For some reason, I am not able to access these pianos although I can access the stock instrum