JTable - One Column Heading for Two Columns

Can you adjust the default JTable to have one column heading for two columns of data? Is there a simple span command? I've looked at the api for JTable and JTableHeader and didn't see anything, is there something I'm missing? Any help would be appreciated.

What i am trying to accomplish is have column 'E' span 2 columns.
This is my code thus far, however it give the error from my pryor message. I am pretty sure it is because I'm using and Object[][] and a String[] instead of Vectors. What corrections do I need to make in order for my goal of:
[ A ][ B ][ C ][ D ][ E  ][ F ][ G ]
[ 1 ][ 2 ][ 3 ][ 4 ][5][6][ 7 ][ 8 ]
Object[][] data = new Object[ROWS][COLUMNS];
String[] columnNames = {"A","B","C","D","E","E","F","G"};
table = new JTable(data, columnNames);
table.setBackground(Color.white);
table.addKeyListener(this);
DefaultTableCellRenderer d = new DefaultTableCellRenderer();
d.setHorizontalAlignment(JLabel.CENTER);
table.setDefaultRenderer(table.getColumnClass(0),d);
for (int i = 0; i < table.getColumnCount(); i++){
TableColumn aColumn = header.getColumnModel().getColumn(i);
TableCellRenderer renderer = aColumn.getHeaderRenderer();
if (renderer == null) {
renderer = new DefaultTableCellRenderer(){
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column){
JTableHeader header = table.getTableHeader();
if (header != null) {
setForeground(header.getForeground());
setBackground(header.getBackground());
setFont(header.getFont());
setHorizontalAlignment(JLabel.CENTER);
setText((value == null) ? "" : value.toString());
setBorder(UIManager.getBorder("TableHeader.cellBorder"));
return this;
aColumn.setHeaderRenderer(renderer);

Similar Messages

  • In Alv_list report column heading in two columns?

    In ALV_List if one the column heading is say for example "Material Description", if i want to display it as "Material" and "Description" below the "Material". Is it possible? if so how?
    For Example:
    Material
    Description
    Thanks in advance.
    Maqsood Ahmed Khan
    Saudia Arab
    [email protected]

    Hi
    No! It's not possible, but you can try to create an your own heading in TOP-OF-PAGE to write the first heading line, the second one will be the std line .
    Max

  • Single heading for Multiple columns in ALV

    Hi Experts,
          I need to display a common column heading for multiple columns in my ALV Grid Display output. I am giving the sample output here.
    MATNR...WERKS..| Unrestricted Stock|....|Stock in transfer        |....|Stock in Quality|.
    ............................| CAT | SAP  | Differe| .. |  CAT   |  SAP  | Diff   | .. | CAT   |  SAP  | Diff  |
    As I shown above, for 3 columns CAT, SAP, and for Difference, I need to get "Unrestricted Stock" as column heading... and so on...
    Pl. suggest me on this.
    Thanks in Advance
    Ramakrishna

    Hello Ramki,
    NOT POSSIBLE IN ALV AT ALL :-((
    You have to use classical report using WRITE stmts for this.
    If your client does not want to lose ALV functionalities, then you can try something like.
    Unrestricted Stock-SAP | Unrestricted Stock-CRM | Unrestricted Stock-Diff. Stock ... and so on !!!
    BR,
    Suhas
    Edited by: Suhas Saha on Jan 21, 2009 3:00 PM

  • Way to wrap Column Heading in two lines

    Hi,
    We have created one table UI element in web dynpro application.
    We have a requirement to wrap a table column heading in the table.
    Is there any way to wrap or keep the column heading in two lines.
    Thanks in advance..
    Regards,
    Kranthi.

    Hi Kranthi,
    not that I know of - but then again that doesn't mean there isn't!
    however, you could force two lines by inserting your column in the table as a column inside a column group - you would get a line for the column group and a line for the column - effectively two lines. If this was the only column in the column group I can't see how it could cause any issue.
    Hope this helps,
    Cheers,
    Chris

  • How to display the column header in two rows?

    Hi Experts,
    I am using ALV_LIST_DISPLAY i neeed to display the column header in two rows.. How can i do that?
    Ex: purchase order i  need to display "purchase" in one row and "order" in second row.
    Thanks in advance,
    Sarath.j

    REPORT zpwtest .
    TYPE-POOLS slis .
    DATA : layout TYPE slis_layout_alv .
    CONSTANTS : c_len TYPE i VALUE 20 .
    TYPES : BEGIN OF ty_t100          ,
              sprsl TYPE t100-sprsl   ,
              arbgb TYPE t100-arbgb   ,
              msgnr TYPE t100-msgnr   ,
              text  TYPE t100-text    ,
              fline TYPE t100-text    ,
            END OF ty_t100            .
    TYPES : BEGIN OF ty_wrd   ,
             text TYPE char20 ,
            END OF ty_wrd     .
    DATA : it_t100     TYPE TABLE OF ty_t100 ,
           it_sentence TYPE TABLE OF ty_wrd  ,
           wa_t100     TYPE ty_t100          ,
           wa_word     TYPE ty_wrd           ,
           v_repid     TYPE syst-repid       ,
           v_tabix     TYPE syst-tabix       .
    DATA : it_fld TYPE slis_t_fieldcat_alv ,
           it_evt TYPE slis_t_event        ,
           wa_fld TYPE slis_fieldcat_alv   ,
           wa_evt TYPE slis_alv_event      .
    INITIALIZATION .
      v_repid = sy-repid .
    START-OF-SELECTION .
    * Get data
      SELECT *
        INTO TABLE it_t100
        FROM t100
       WHERE sprsl = 'EN'
         AND arbgb = '00' .
      LOOP AT it_t100 INTO wa_t100 .
        v_tabix = sy-tabix .
        CLEAR : it_sentence .
        CALL FUNCTION 'RKD_WORD_WRAP'
             EXPORTING
                  textline  = wa_t100-text
                  outputlen = c_len
             TABLES
                  out_lines = it_sentence.
        IF NOT it_sentence IS INITIAL .
          READ TABLE it_sentence INTO wa_word INDEX 1 .
          wa_t100-fline = wa_word-text .
          MODIFY it_t100 FROM wa_t100 INDEX v_tabix .
        ENDIF.
      ENDLOOP.
    * Prepare fieldcatelog
      CLEAR wa_fld .
      wa_fld-fieldname = 'SPRSL' .
      wa_fld-ref_tabname = 'T100' .
      wa_fld-ref_fieldname = 'SPRSL' .
      APPEND wa_fld TO it_fld .
      CLEAR wa_fld .
      wa_fld-fieldname = 'ARBGB' .
      wa_fld-ref_tabname = 'T100' .
      wa_fld-ref_fieldname = 'ARBGB' .
      APPEND wa_fld TO it_fld .
      CLEAR wa_fld .
      wa_fld-fieldname = 'MSGNR' .
      wa_fld-ref_tabname = 'T100' .
      wa_fld-ref_fieldname = 'MSGNR' .
      APPEND wa_fld TO it_fld .
      CLEAR wa_fld .
      wa_fld-fieldname = 'FLINE' .
      wa_fld-inttype      = 'CHAR' .
      wa_fld-outputlen = 20 .
      wa_fld-intlen    = 20.
      wa_fld-seltext_l = 'Text' .
      wa_fld-ddictxt = 'L' .
      APPEND wa_fld TO it_fld .
    * Get event.. we will handle BOFORE and AFTER line output
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
           IMPORTING
                et_events = it_evt.
      READ TABLE it_evt INTO wa_evt
      WITH KEY name = slis_ev_after_line_output .
      wa_evt-form = slis_ev_after_line_output .
      MODIFY it_evt FROM wa_evt INDEX sy-tabix .
      READ TABLE it_evt INTO wa_evt
      WITH KEY name = slis_ev_top_of_page .
      wa_evt-form = slis_ev_top_of_page .
      MODIFY it_evt FROM wa_evt INDEX sy-tabix .
      layout-no_colhead = 'X' .
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
           EXPORTING
                i_callback_program = v_repid
                it_fieldcat        = it_fld
                is_layout          = layout
                it_events          = it_evt
           TABLES
                t_outtab           = it_t100.
    *       FORM top_of_page                                              *
    FORM top_of_page .
        uline .
        WRITE: / sy-vline     ,
               10 sy-vline    ,
               11 'line1'     ,
               31 sy-vline    ,
               37 sy-vline    ,
               58 sy-vline    .
        WRITE: / sy-vline     ,
               10 sy-vline    ,
               11 'line2'     ,
               31 sy-vline    ,
               37 sy-vline    ,
               58 sy-vline    .
        WRITE: / sy-vline     ,
               10 sy-vline    ,
               11 'line3'     ,
               31 sy-vline    ,
               37 sy-vline    ,
               58 sy-vline    .
    ENDFORM.
    *       FORM AFTER_LINE_OUTPUT                                        *
    FORM after_line_output   USING rs_lineinfo TYPE slis_lineinfo .
      CLEAR : it_sentence ,
              wa_t100     .
      READ TABLE it_t100 INTO wa_t100 INDEX rs_lineinfo-tabindex .
      CHECK sy-subrc = 0 .
      CALL FUNCTION 'RKD_WORD_WRAP'
           EXPORTING
                textline  = wa_t100-text
                outputlen = c_len
           TABLES
                out_lines = it_sentence.
      DESCRIBE TABLE it_sentence LINES v_tabix .
      CHECK v_tabix > 1 .
      LOOP AT it_sentence INTO wa_word FROM 2 .
        WRITE: / sy-vline     ,
               10 sy-vline    ,
               31 sy-vline    ,
               37 sy-vline    ,
               38 wa_word-text ,
               58 sy-vline .
      ENDLOOP.
    ENDFORM .

  • Multiple column heading for sql that returns single column

    Hi All,
    I have just started using APEX and my apex version is 3.2.0.00.27.
    We have a report that displays the output from a query similar to the below one. We are using borderless template and removed the "before each row" and "after each row" values to allow the output displayed in table format.
    Now we wanted to include heading for each column displayed in table. We wanted to include headings from a derived value, Example for column1 , heading need to display the sysdate and column2 heading should be sysdate-1 and so on.  But the column attribute tab is having only one column My_rep. Not sure how to se pl/sql type column heading in this case. Could someone please help me to achieve this?
    Please let me know if I have missed to provide any other details. Thanks in advance.
    select '<tr>
        <td>' || column1    || '</td>' ||
        <td>' || column2    || '</td>' ||
        <td>' || column3    || '</td>' ||
        <td>' || column4    || '</td>' ||
        || '</tr>' My_rep
    from mytable

    22335813-cfb0-46c4-9bef-b61a46f0de67 wrote:
    Please update your forum profile with a real handle instead of "22335813-cfb0-46c4-9bef-b61a46f0de67"
    I have just started using APEX and my apex version is 3.2.0.00.27.
    Upgrading from this unsupported version to the current 4.2 release is recommended.
    When you post a question, always include the following information in addition to the full APEX version number:
    Full database version, edition and host OS
    Web server architecture (EPG, OHS or APEX listener), server platform, and host OS
    Browser(s)/version(s) used
    UI/Theme
    Templates
    Region type (making particular distinction as to whether a "report" is a standard report, an interactive report, or in fact an "updateable report" (i.e. a tabular form)
    With APEX we're also fortunate to have a great resource in apex.oracle.com where we can reproduce and share problems. Reproducing things there is the best way to troubleshoot most issues, especially those relating to layout and visual formatting. To get a detailed answer then it's appropriate for the questioner to take on a significant part of the effort by reproducing the problem on apex.oracle.com before asking for assistance with specific issues, which can then be seen at first hand in a real APEX environment.
    we wanted to get a report in Apex with the below format. and we wanted to change background color of each cell depends on the combination of code||status
    Heading        sysdate             sysdate-1              sysdate-2                              ...(sysdate-30
    ======        ======          ========               =======
    name         code||status                                   code||status
    name                                  code||status
    we are using the below query to get this table format. But heading is the issue we are facing now
    select '<tr>
        <td>' || name    || '</td>' ||
        '<td style=background-color:' || case when sysdate0='0C' then 'Green' when sysdate0='0I' then 'Red'     when (substr(sysdate0,1,1)!='0' and substr(sysdate0,1,1)='I') then 'Orange'  else 'Yellow' end || '>  &nbsp'  || sysdate0 || '  &nbsp</td>'  ||
        || '</tr>' repcolumn
    from
      (select
            a.name,
            max(decode(trunc(a.ardate),trunc(sysdate), a.code||a.STATUS , '' ))   sysdate0,
            max(decode(trunc(a.ardate),trunc(sysdate-30), a.code||a.STATUS , '' )) sysdate30
    from
            mytab a
    where
            a.ardate>=sysdate-30
    group by a.name)
    See Re: Matrix report for a custom report template-based solution to a similar problem, with dynamically generated column headings.

  • How to display a Column Header for the characteristic Text column

    Hi All
    Our users want me to provide for a column header for the characteristic text.
    Here is what I mean
    I am reporting 0plant in the rows as key and Text. In the column on Plant Key the column header says Plant but there is no column header for the plant text.
    Eq:
    Plant                                                        Amount
    IE00         Initiator Plant                               244
    IE01         Initiator Plant NJ                          890
    Our users in the plant text column want a dummy column header to be displayed. SInce they download the data from the BW report to Excel and use pivot reporting. How can I introduce a column header for the texts.
    Thanks
    Karen

    Hi Karen,
    I am not sure if this is possible, although Users can ask anything :).
    In Planning we used to predefine cell headings via Macros and creating dummy cells in between.  I am not sure if a similar scenario can work here.
    By default this is not possible in Reports.  In BEx workbooks, you could probably try with Macros.
    Another easy option is to bring the data in the Cube as another field or create a nav. attribute in the master for text and use it as a nav. attr. in the Cube and put it in your Query row alongside.
    -Aby

  • How To avoid column heading for only total line in ALV list Display

    Hi,
    How To avoid column heading for only total line in ALV list Display.

    Hi,
    to change colunm header field catlog is built
    look at the example below
    Changing column text headers
    use this to change, hide, or alter the ALV columns
    CLEAR: gt_fcat.
    READ TABLE gt_fcat WITH KEY fieldname = 'TEXT1' " ***
    *TEXT1 is your field name
       ASSIGNING <gtfcat>.
    IF sy-subrc = 0.
       <gtfcat>-coltext   = 'Date Type'.
       <gtfcat>-no_out    = ' '.
       <gtfcat>-tooltip   = 'Date Type Text from IT0019'.
       <gtfcat>-seltext   = 'IT0019'.
    keep seltext to '' if u want to hide
    ENDIF.
    regards
    austin

  • Header for each column of data

    I am struggling to get header for each column in attached code. I would like to see this data in excel with header at the top. Also I wonder how to know which column belongs to which plot and which axis.
    Solved!
    Go to Solution.
    Attachments:
    saving for excel.vi ‏130 KB

    I would keep this in the original thread.

  • HT204053 Can I use one Apple ID for two Apple IPhones?

    Can I use one Apple ID for two Apple IPhones? I received an answer of yes.
    Now another question.  I have one ICloud Account, Two IPhones.  Can I use Find my IPhone via the one ICloud Account?  Can I see two IPhones on the map at the same time?  or do I need to view the second phone via some other method.
    Message was edited by: Hunter3D

    Yes.
    Cheers,
    GB

  • One apple id for two iPhone

    Is it possible tou use just one aple id for two iPhones?

    Read here:
    http://support.apple.com/kb/HT1495

  • Can I use one gift card for two apple ID at the same time?

    Can I activate one gift card for two different apple ID and use amount from gift card like bank account?

    No, an iTunes gift card can only be redeemed onto one account, and it can be used to buy content for that account (you can't, for example, redeem it on an account and then use some of it for gifting content to another account).

  • Can I use one iCloud account for two phones without sharing contacts

    Can I use one iCloud account for two phones without sharing contacts

    If so how do I unmerge the two phones?

  • Use one store account for two I pads. Get request for security code

    Trying to use one store account for two I pads. One works fine, the other is unable to download a free app, window asks for security code.?.......
    What security code?

    Probably the security code on your credit card

  • Is it ok to use one apple id for two devices ?

    is it ok to use one apple id for two devices ?

    Here's the deal: The SLA permits the "sharing" of content with up to 5 family members in the same household. Any other distribution of content is considered stealing...the SLA does not give you the right to distribute content in any way, shape or form. Its really that simple, and "friend" is NOT a family member living in the same household.

Maybe you are looking for