Two colors in a cell ALV

Hi All,
I want to produce a report in ALV , where I have to print two diff colors in a cell..
Eg:       In a cell  128(38)  
128(    ) in black and 38 in red.
Thanks in advance.
Balamurugan.R

hi,
see the below example which may be useful.
types:  begin of ty_vbak,
        Vbeln type vbeln_va,
        erdat type erdat,
        ernam type ernam,
cellcolors type lvc_t_scol,  " table type for cell coloring
cellstyles TYPE lvc_t_styl,  " table type for Style Table for Cells
        end of ty_vbak.
data:  t_vbak type table of ty_vbak,
       w_vbak type ty_vbak.
data: gt_fieldcat type lvc_t_fcat,
      gs_fieldcat like line of gt_fieldcat,
      gw_layout type lvc_s_layo.
Reference to Custom container
DATA: G_CUSTOM_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER,
       G_CONTAINER TYPE SCRFNAME VALUE  'CC_ALV',
    G_GRID TYPE REF TO CL_GUI_ALV_GRID,
*&      Module  STATUS_0001  OUTPUT
      text
MODULE STATUS_0001 OUTPUT.
SET PF-STATUS 'xxxxxxxx'.
SET TITLEBAR 'xxx'.
CREATE OBJECT G_CUSTOM_CONTAINER
   EXPORTING
    PARENT                      =
     CONTAINER_NAME              = G_CONTAINER
    STYLE                       =
    LIFETIME                    = LIFETIME_DEFAULT
    REPID                       =
    DYNNR                       =
    NO_AUTODEF_PROGID_DYNNR     =
  EXCEPTIONS
    CNTL_ERROR                  = 1
    CNTL_SYSTEM_ERROR           = 2
    CREATE_ERROR                = 3
    LIFETIME_ERROR              = 4
    LIFETIME_DYNPRO_DYNPRO_LINK = 5
    OTHERS                      = 6
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
  CREATE OBJECT G_GRID
    EXPORTING
     I_SHELLSTYLE      = 0
     I_LIFETIME        =
      I_PARENT          =  G_CUSTOM_CONTAINER
     I_APPL_EVENTS     = SPACE
     I_PARENTDBG       =
     I_APPLOGPARENT    =
     I_GRAPHICSPARENT  =
     I_NAME            =
     I_FCAT_COMPLETE   = SPACE
   EXCEPTIONS
     ERROR_CNTL_CREATE = 1
     ERROR_CNTL_INIT   = 2
     ERROR_CNTL_LINK   = 3
     ERROR_DP_CREATE   = 4
     OTHERS            = 5
  IF SY-SUBRC <> 0.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
perform populate_data.
perform fieldcat.
perform populate_layout.
perform display_output.
ENDMODULE.                 " STATUS_0001  OUTPUT
*&      Form  populate_data
      populating the data
-->  p1        text
<--  p2        text
FORM populate_data .
  data: color(1) type c.
DATA lw_cellcolor TYPE lvc_s_scol . "line type for cell coloring
select  vbeln
        erdat
        ernam from vbak into CORRESPONDING FIELDS OF TABLE t_vbak up to 10 rows.
*coloring the particular cell.
READ TABLE t_vbak INTO w_vbak  INDEX 5 .
lw_cellcolor-fname = 'ERDAT' .
lw_cellcolor-color-col = '4' .
lw_cellcolor-color-int = '1' .
APPEND lw_cellcolor TO w_vbak-cellcolors .
modify t_vbak index 5 from w_vbak.
READ TABLE t_vbak INTO w_vbak  INDEX 7.
lw_cellcolor-fname = 'ERNAM' .
lw_cellcolor-color-col = '7' .
lw_cellcolor-color-int = '1' .
APPEND lw_cellcolor TO w_vbak-cellcolors .
modify t_vbak index 7 from w_vbak.
ENDFORM.                    " populate_data
*&      Form  fieldcat
      populatin the fieldcat
-->  p1        text
<--  p2        text
FORM fieldcat .
  clear gs_fieldcat.
  gs_fieldcat-fieldname = 'VBELN'.
  gs_fieldcat-tabname = 'T_VBAk'.
  gs_fieldcat-outputlen = '20'.
  gs_fieldcat-SCRTEXT_M = 'DOCUMENT NUMBER'.
  append gs_fieldcat to GT_fieldcat.
  clear gs_fieldcat.
  gs_fieldcat-fieldname = 'ERDAT'.
  gs_fieldcat-tabname = 'T_VBAK'.
  gs_fieldcat-outputlen = '20'.
  gs_fieldcat-SCRTEXT_M = 'CREATED ON'.
  append gs_fieldcat to GT_fieldcat.
  clear gs_fieldcat.
  gs_fieldcat-fieldname = 'ERNAM'.
  gs_fieldcat-tabname = 'T_VBAK'.
  gs_fieldcat-outputlen = '20'.
  gs_fieldcat-SCRTEXT_M = 'CREATED BY'.
  append gs_fieldcat to GT_fieldcat.
ENDFORM.                    " fieldcat
*&      Form  display_output
      text
-->  p1        text
<--  p2        text
FORM display_output .
  CALL METHOD G_GRID->SET_TABLE_FOR_FIRST_DISPLAY
    EXPORTING
     I_BUFFER_ACTIVE               =
     I_BYPASSING_BUFFER            =
     I_CONSISTENCY_CHECK           =
     I_STRUCTURE_NAME              =
     IS_VARIANT                    =
     I_SAVE                        =
     I_DEFAULT                     = 'X'
    IS_LAYOUT                      = gw_layout
     IS_PRINT                      =
     IT_SPECIAL_GROUPS             =
   IT_TOOLBAR_EXCLUDING           = *      IT_HYPERLINK                  =
     IT_ALV_GRAPHICS               =
     IT_EXCEPT_QINFO               =
     IR_SALV_ADAPTER               =
    CHANGING
      IT_OUTTAB                      = t_vbak
      IT_FIELDCATALOG                = GT_fieldcat
     IT_SORT                       =
     IT_FILTER                     =
   EXCEPTIONS
     INVALID_PARAMETER_COMBINATION = 1
     PROGRAM_ERROR                 = 2
     TOO_MANY_LINES                = 3
     OTHERS                        = 4
  IF SY-SUBRC <> 0.
  MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
*&      Form  populate_layout
      populating the layout
     <--P_GW_LAYOUT   internal table for the layput
FORM populate_layout."  CHANGING P_GW_LAYOUT type lvc_s_layo.
gw_layout-zebra = 'X'.
gw_layout-ctab_fname = 'CELLCOLORS'. "cell coloring
*gw_layout-info_fname = 'ROW_COLOR'.    "row coloring
gw_layout-stylefname = 'CELLSTYLES'.   "styles
ENDFORM.                    " populate_layout
thanks and regards

Similar Messages

  • How to Fill two color's

    HAPPY NEW YEAR
    Hi,
    How to fill two color's in cell of jtable.
    Exactly i need to fill Yellow background and on some conditions i need to put Red on Top-Right-Corner of the cell.
    Thank's

    Check you the reply you got in your other posting on this topic:
    http://forum.java.sun.com/thread.jspa?threadID=5119850

  • ALV color a particular cell on meeting certain condition

    hi all
         i am working with ALV , my requirement is to color a particular cell if condition mate.
    like .
       i have two fields in my ITAB  PlanedCost and ActualCost
    If ACTUALCOST is >= 80% of PLANEDCOST then
    ACTUALCOST cell must come in RED COLOR.
    how to do so .
    please guide me.

    Hi Rock,
            I tried a program to color a cell based on its value, but it is not working. Am pasting the code below and please can u exactly tell me what is the problem it.
    *& Report  ZSAPCOLV
    REPORT  zsapcolv.
    TABLES:mara.
    TYPES:BEGIN OF ty_mara,
          matnr TYPE mara-matnr,
          mtart TYPE mara-mtart,
          color1(4),
         END OF ty_mara.
    DATA:it_mara TYPE STANDARD TABLE OF ty_mara,
         it_color  TYPE TABLE  OF lvc_s_scol,
         wa_mara TYPE ty_mara,
         wa_color    TYPE lvc_s_scol,
         is_layout   TYPE lvc_s_layo.
    DATA: t_newtable TYPE REF TO data,
    t_newline  TYPE REF TO data.
    FIELD-SYMBOLS: <dyntab> TYPE STANDARD TABLE,
                   <wa_dyntab> TYPE ANY,
                   <gfs_wa> TYPE ANY.
    TYPES: BEGIN OF ty_cmara,
        matnr TYPE mara-matnr,
         mtart TYPE mara-mtart,
       tabcolor TYPE lvc_t_scol,
    END OF ty_cmara.   " Cell color
    DATA:it_cmara TYPE STANDARD TABLE OF ty_cmara.
    DATA:
          gr_table     TYPE REF TO cl_salv_table,
          gr_functions TYPE REF TO cl_salv_functions,
          gr_display   TYPE REF TO cl_salv_display_settings.
    DATA:   it_fcat TYPE lvc_t_fcat,
            wa_fcat TYPE lvc_s_fcat.
    DATA:it_fcat1 TYPE lvc_t_fcat, "with cell color
         it_fcat2 TYPE lvc_t_fcat,
    wa_fieldcat LIKE LINE OF it_fcat1,
    wa_cellcolors TYPE lvc_s_scol,
    wa_is_layout TYPE lvc_s_layo.
    FIELD-SYMBOLS:<t_cellcolors> TYPE lvc_t_scol,
    <w_field> TYPE ANY.
    DATA:t_line  TYPE REF TO data .
    *-----design selection screen for plant and material type.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-b01.
    SELECT-OPTIONS:
                     s_matnr     FOR mara-matnr.    "material type
    SELECTION-SCREEN END OF BLOCK b1.
    START-OF-SELECTION.
      PERFORM fetch_data.
      PERFORM display_data.
    *&      Form  fetch_data
    FORM fetch_data .
      DATA:wa_cmara TYPE ty_cmara.
      DATA: ls_tabcolor TYPE lvc_s_scol.
      SELECT
    FROM mara
        INTO CORRESPONDING FIELDS OF TABLE it_mara WHERE matnr IN s_matnr.
      CHECK sy-subrc EQ 0.
      PERFORM build_catalog USING '1' 'MATNR' 'Material number' 'Material Number' ' ' '18'.
      PERFORM build_catalog USING '1' 'MTART' 'Material type' 'Material type' ' ' '10'.
      it_fcat1[] = it_fcat[].
       wa_fieldcat-fieldname = 'T_CELLCOLORS'.
       wa_fieldcat-ref_field = 'COLTAB'.
       wa_fieldcat-ref_table = 'CALENDAR_TYPE'.
      APPEND wa_fieldcat TO it_fcat.
      cl_alv_table_create=>create_dynamic_table( EXPORTING it_fieldcatalog = it_fcat
                                                  IMPORTING ep_table = t_newtable ).
      ASSIGN t_newtable->* TO <dyntab>.
      CREATE DATA t_line LIKE LINE OF <dyntab>.
      ASSIGN t_line->* TO <gfs_wa>.
      PERFORM fill_data.
    ENDFORM.                    " fetch_data
    *&      Form  build_catalog
    FORM build_catalog  USING    p_pos TYPE lvc_colpos
                           p_field TYPE lvc_fname
                           p_reptext TYPE reptext
                           p_coltext TYPE coltext
                           p_check TYPE lvc_checkb
                           p_len TYPE lvc_outlen.
      wa_fcat-col_pos    = p_pos.
      wa_fcat-fieldname  = p_field.
      wa_fcat-reptext    = p_reptext.
      wa_fcat-checkbox   = p_check.
      wa_fcat-outputlen  = p_len.
      wa_fcat-emphasize = '6'.
      IF p_check = 'X'.
        wa_fcat-edit = 'X'.
      ENDIF.
      APPEND wa_fcat TO it_fcat.
      CLEAR wa_fcat.
    ENDFORM.                    " catalog
    *&      Form  fill_data
    FORM fill_data .
      FIELD-SYMBOLS: <wa_tmp> TYPE ANY,
                     <v_fld> TYPE ANY,
                     <color> TYPE ANY,
                     <wa_color> TYPE lvc_s_scol.
      DATA: v_fld(20).
      DATA : lv_cnt TYPE i,
             t_newline1  type ref to data,
             lv_cnt1 TYPE i.
        FIELD-SYMBOLS: <ta_color> TYPE lvc_t_scol.
         DATA : field(15) TYPE c,
             col TYPE lvc_s_scol.
      create data t_newline1 LIKE <wa_color>.
      LOOP AT it_mara INTO wa_mara.
        lv_cnt1 = lv_cnt1 + 1.
        LOOP AT it_fcat INTO wa_fcat.
          UNASSIGN <wa_tmp>.
          ASSIGN COMPONENT wa_fcat-fieldname OF STRUCTURE <gfs_wa> TO <wa_tmp>.
          CONCATENATE 'WA_MARA-' wa_fcat-fieldname INTO v_fld.
          ASSIGN (v_fld) TO <v_fld>.
          CHECK sy-subrc EQ 0.
          IF <v_fld> = '000000000000000004'.
             col-fname = wa_fcat-fieldname.
             col-color-col = '5' .
             col-color-int = '0' .
              "ASSIGN COMPONENT wa_fcat-fieldname OF STRUCTURE <gfs_wa> TO <ta_color>.
               ASSIGN COMPONENT 'T_CELLCOLORS' OF STRUCTURE <gfs_wa> TO <ta_color> .
               APPEND col TO <ta_color>.
            <wa_tmp> = <v_fld>.
            lv_cnt = lv_cnt + 1.
          ENDIF.
          IF lv_cnt = 1.
            APPEND <gfs_wa> TO <dyntab>.
          ELSE.
            MODIFY <dyntab> INDEX lv_cnt1 FROM <gfs_wa>.
          ENDIF.
        ENDLOOP.
        lv_cnt = 0.
        CLEAR wa_mara.
      ENDLOOP.
    ENDFORM.                    " fill_data
    *&      Form  display_data
    FORM display_data .
    IF <dyntab> IS NOT INITIAL.
       LOOP AT <dyntab> INTO <gfs_wa>.
         ASSIGN COMPONENT 'MATNR' OF STRUCTURE <gfs_wa> TO <w_field>.
         ASSIGN COMPONENT 'T_CELLCOLORS' OF STRUCTURE <gfs_wa> TO <t_cellcolors> .
         CLEAR wa_cellcolors.
        "wa_cellcolors-fname = 'MATNR'.
         "IF <w_field> = '000000000000000004'.
           "FORMAT INTENSIFIED COLOR = 6.
           wa_cellcolors-fname = 'MATNR'.
           wa_cellcolors-color-col = '7'.
           wa_cellcolors-color-int = '1'.
           "wa_cellcolors-color-inv = '1'.
           "wa_cellcolors-NOKEYCOL = ''.
          "ELSE.
          "wa_cellcolors-color-col = '5'.
        "ENDIF.
         APPEND wa_cellcolors TO <t_cellcolors>.
         MODIFY <dyntab> FROM <gfs_wa>.
       ENDLOOP.
      cl_salv_table=>factory( IMPORTING r_salv_table = gr_table CHANGING t_table = <dyntab> ).
      gr_functions = gr_table->get_functions( ).
      gr_functions->set_all( abap_true ).
      gr_display = gr_table->get_display_settings( ).
      gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
      gr_display->set_list_header( 'MARA DATA' ).
      gr_table->display( ).
      "ENDIF.
    ENDFORM.                    " display_data

  • ALV color priority:  The layout color or the cell color?

    I'm trying to assign an ALV at the cell level but it is not showing up.  I have specificed the column color at the layout level.  Does the layout level have color priority?

    Hi
    see the doc and do accordingly
    1. add one more field to ur final internal table say COLOR(4)
    2. in layout wa_layout-style_fname = 'COLOR'. " if its grid
    wa_layout-style_fieldname = 'COLOR'. "if its list
    3. read table itab index 3.
    itab-color = 'C410'.
    modify itab index 3
    4. see program SHOWCOLO for all color codes
    1. Add a field of data type CHAR(3) to the internal output table.
    2. Enter the color code in the appropriate field of the row to be colored in the internal
    output table:
    Code: 'Cxy'
    C = Color (all codes begin with 'C')
    x = color number ('1' - '9')
    y = highlight ('0' = off, '1' = on)
    3. Assign the internal output table color code field name to the IS_LAYOUT importing
    structure IS_LAYOUT-INFO_FIELDNAME field and pass this structure in the ALV call
    interface.
    To enable row coloring, you should add an additional field to your list data table. It should be of character type and length at least 4. This field will contain the color code for the row. So, let’s modify declaration of our list data table “gt_list”.
    you should fill the color code to this field. Its format will be the same as explained before at section C.6.3. But how will ALV Grid know that you have loaded the color data for the row to this field. So, you make it know this by passing the name of the field containing color codes to the field “INFO_FNAME” of the layout structure.
    e.g.
    ps_layout-info_fname = <field_name_containing_color_codes>. “e.g. ‘ROWCOLOR’
    You can fill that field anytime during execution. But, of course, due to the flow logic of screens, it will be reflected to your list display as soon as an ALV refresh occurs.
    You can color an entire row as described in the next section. However, this method is less time consuming.
    Coloring Individual Cells
    This is the last point about coloring procedures for the ALV Grid. The procedure is similar to coloring an entire row. However, since an individual cell can be addressed with two parameters we will need something more. What is meant by “more” is a table type structure to be included into the structure of the list data table. It seems strange, because including it will make our list data structure deep. But anyhow ALV Grid control handles this.
    The structure that should be included must be of type “LVC_T_SCOL”. If you want to color the entire row, this inner table should contain only one row with field “fname” is set to space, some color value at field “col”, “0” or “1” at fields “int” (intensified) and “inv” (inverse).
    If you want to color individual cells, then for each cell column, append a line to this inner table which also contains the column name at field “fname”. It is obvious that you can color an entire column by filling this inner table with a row for that column for each row in the list data table.
    Regards
    Anji

  • How to color a specific cell in ALV (not REUSE_ALV_GRID_DISPLAY)

    Hi
    I want to change color font or background to a specify position in ALV grid
    It is possible but by creating ALV container (not FM for example REUSE_ALV_GRID_DISPLAY)?

    Hi,
    REPORT ZALV_LIST1.
    TABLES:
    SPFLI.
    TYPE-POOLS:
    SLIS.
    PARAMETERS:
    P_COL TYPE I ,
    P_ROW TYPE I,
    P_COLOR(4) TYPE C .
    DATA:
    T_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
    FS_FIELDCAT LIKE LINE OF T_FIELDCAT,
    FS_LAYOUT TYPE SLIS_LAYOUT_ALV ,
    W_COLOR(4) ,
    W_ROW TYPE I,
    W_FIELDNAME(20),
    W_PROG TYPE SY-REPID.
    DATA:
    BEGIN OF T_SPFLI OCCURS 0,
    COLOR(4),
    CHECKBOX ,
    CELL TYPE SLIS_T_SPECIALCOL_ALV,
    CARRID TYPE SPFLI-CARRID,
    CONNID TYPE SPFLI-CONNID,
    CITYFROM TYPE SPFLI-CITYFROM,
    CITYTO TYPE SPFLI-CITYTO,
    DISTANCE TYPE SPFLI-DISTANCE,
    END OF T_SPFLI.
    DATA:
    FS_CELL LIKE LINE OF T_SPFLI-CELL.
    SELECT *
    FROM SPFLI
    INTO CORRESPONDING FIELDS OF TABLE T_SPFLI.
    W_COLOR = P_COLOR.
    T_SPFLI-COLOR = P_COLOR.
    IF P_COL IS INITIAL AND P_ROW GT 0.
    MODIFY T_SPFLI INDEX P_ROW TRANSPORTING COLOR.
    ENDIF.
    FS_FIELDCAT-FIELDNAME = 'CARRID'.
    FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
    FS_FIELDCAT-COL_POS = 1.
    FS_FIELDCAT-KEY = 'X'.
    FS_FIELDCAT-HOTSPOT = 'X'.
    APPEND FS_FIELDCAT TO T_FIELDCAT.
    CLEAR FS_FIELDCAT .
    FS_FIELDCAT-FIELDNAME = 'CONNID'.
    FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
    FS_FIELDCAT-COL_POS = 2.
    FS_FIELDCAT-KEY = 'X'.
    FS_FIELDCAT-HOTSPOT = 'X'.
    APPEND FS_FIELDCAT TO T_FIELDCAT.
    CLEAR FS_FIELDCAT .
    FS_FIELDCAT-FIELDNAME = 'DISTANCE'.
    FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
    FS_FIELDCAT-COL_POS = 3.
    FS_FIELDCAT-KEY = ' '.
    FS_FIELDCAT-EDIT = 'X'.
    APPEND FS_FIELDCAT TO T_FIELDCAT.
    CLEAR FS_FIELDCAT.
    FS_FIELDCAT-FIELDNAME = 'CITYFROM'.
    FS_FIELDCAT-REF_TABNAME = 'SPFLI'.
    FS_FIELDCAT-COL_POS = 4.
    FS_FIELDCAT-KEY = ' '.
    APPEND FS_FIELDCAT TO T_FIELDCAT.
    LOOP AT T_FIELDCAT INTO FS_FIELDCAT.
    IF FS_FIELDCAT-COL_POS EQ P_COL.
    FS_FIELDCAT-EMPHASIZE = P_COLOR.
    W_FIELDNAME = FS_FIELDCAT-FIELDNAME.
    IF P_ROW IS INITIAL AND P_COL GT 0.
    MODIFY T_FIELDCAT FROM FS_FIELDCAT TRANSPORTING EMPHASIZE.
    ENDIF.
    ENDIF.
    ENDLOOP.
    FS_CELL-FIELDNAME = W_FIELDNAME .
    FS_CELL-COLOR-COL = 6.
    FS_CELL-NOKEYCOL = 'X'.
    APPEND FS_CELL TO T_SPFLI-CELL.
    IF P_ROW IS NOT INITIAL AND P_COL IS NOT INITIAL.
    MODIFY T_SPFLI INDEX P_ROW TRANSPORTING CELL.
    ENDIF.
    FS_LAYOUT-INFO_FIELDNAME = 'COLOR'.
    FS_LAYOUT-BOX_FIELDNAME = 'CHECKBOX'.
    FS_LAYOUT-COLTAB_FIELDNAME = 'CELL'.
    FS_LAYOUT-F2CODE = '&ETA'.
    W_PROG = SY-REPID.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
    I_CALLBACK_PROGRAM = W_PROG
    IS_LAYOUT = FS_LAYOUT
    IT_FIELDCAT = T_FIELDCAT
    TABLES
    T_OUTTAB = T_SPFLI
    EXCEPTIONS
    PROGRAM_ERROR = 1
    OTHERS = 2

  • Display Color for sigle  CELL in ALV report

    Hi all,
    I have one doubt is it possible to make a particular cell as read color in ALV.
    Ex: I have one field which shows amount in my ALV report,My requirement is that when ever the amount is less then 'ZERO', I have to show that particular cell in read color.
    Regards
    Anil Kumar.N

    hi,
    here code for coloring a perticular cell
    TYPE-POOLS:slis.
    TABLES:mara,
           makt,
           marc.
    DATA:BEGIN OF itab OCCURS 0,
          matnr LIKE mara-matnr,
          maktx LIKE makt-maktx,
          werks LIKE marc-werks,
          mtart LIKE mara-mtart,
          matkl LIKE mara-matkl,
          meins LIKE mara-meins,
          ntgew LIKE mara-ntgew,
         rowcolor(4) TYPE c,
          cellcolors TYPE lvc_t_scol,
         END OF itab.
    DATA:t_fcat TYPE slis_t_fieldcat_alv,
         t_eve TYPE slis_t_event.
    DATA : st_layout TYPE slis_layout_alv.
    SELECTION-SCREEN:BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.
    SELECT-OPTIONS:mat FOR mara-matnr.  " no intervals no-extension.
    *PARAMETERS:mat LIKE mara-matnr.
    SELECTION-SCREEN:END OF BLOCK blk1.
    INITIALIZATION.
      PERFORM build_cata USING t_fcat.
      PERFORM build_event.
    START-OF-SELECTION.
      PERFORM data_retrieval.
      PERFORM display_data.
    *&      Form  build_cata
          text
         -->TEMP_FCAT  text
    FORM build_cata USING temp_fcat TYPE slis_t_fieldcat_alv.
      sy-tvar0 = sy-uname.
      WRITE sy-datum TO sy-tvar1.
      DATA:wa_fcat TYPE slis_fieldcat_alv.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'MATNR'.
      wa_fcat-seltext_m = 'Material'.
      APPEND wa_fcat TO temp_fcat.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'MAKTX'.
      wa_fcat-seltext_m = 'Description'.
      wa_fcat-fix_column = 'x'.
      wa_fcat-key = 'X'.                                     "To color a column
      APPEND wa_fcat TO temp_fcat.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'WERKS'.
      wa_fcat-seltext_m = 'Plant'.
      wa_fcat-key = ' '.
      APPEND wa_fcat TO temp_fcat.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'MTART'.
      wa_fcat-seltext_m = 'Type'.
      APPEND wa_fcat TO temp_fcat.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'MATKL'.
      wa_fcat-seltext_m = 'Group'.
      APPEND wa_fcat TO temp_fcat.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'MEINS'.
      wa_fcat-seltext_m = 'Measurement Unit'.
      APPEND wa_fcat TO temp_fcat.
      wa_fcat-tabname = 'ITAB'.
      wa_fcat-fieldname = 'NTGEW'.
      wa_fcat-seltext_m = 'Net Value'.
      APPEND wa_fcat TO temp_fcat.
    ENDFORM.                    "build_cata
    *&      Form  build_event
          text
    FORM build_event.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
        EXPORTING
          i_list_type     = 0
        IMPORTING
          et_events       = t_eve
        EXCEPTIONS
          list_type_wrong = 1
          OTHERS          = 2.
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    "build_event
    *&      Form  data_retrieval
          text
    FORM data_retrieval.
      SELECT maramatnr  maramtart maramatkl marameins mara~ntgew
       maktmaktx  marcwerks
      INTO CORRESPONDING FIELDS OF TABLE itab
      FROM mara INNER JOIN makt ON
      maramatnr = maktmatnr
      INNER JOIN marc ON
      maramatnr = marcmatnr
      WHERE mara~matnr IN mat.
      SORT itab BY matnr.
      DELETE ADJACENT DUPLICATES FROM itab.
    ENDFORM.                    "data_retrieval
    *&      Form  display_data
          text
    FORM display_data.
    *******************************For setting Cell Color*******************************************
      DATA ls_cellcolor TYPE lvc_s_scol .
      st_layout-coltab_fieldname = 'CELLCOLORS'.
      READ TABLE itab INDEX 5 .
      ls_cellcolor-fname = 'MATNR' .
      ls_cellcolor-color-col = '1' .
      ls_cellcolor-color-int = '1' .
      APPEND ls_cellcolor TO itab-cellcolors .
      MODIFY itab INDEX 5 .
    st_layout-colwidth_optimize = 'X'.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program = 'ZALV_DS'
          is_layout          = st_layout
          i_save             = 'A'
          it_fieldcat        = t_fcat
          it_events          = t_eve
        TABLES
          t_outtab           = itab
        EXCEPTIONS
          program_error      = 1
          OTHERS             = 2.
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    "display_data
    Please reward if useful...

  • Ask split long text into two line into same cell for ALV

    Dear All,
    Is it possible split long text into two line into same cell for ALV display data?
    Regards,
    Luke
    Moderator message: please search for information before asking.
    Edited by: Thomas Zloch on Feb 24, 2011 10:12 AM

    Keep options: Select the paragraph, then CtrlAltK (Mac: CmdOptK, I
    think).
    If you want the paragraphs in pairs, create two paragraph styles. Style
    A has keep options set to start on a new page, and also, its Next Style
    is style B.
    Style B has no keep options, but it's Next Style is Style A.
    Select all the text.
    From the flyout menu of the paragraph styles palette, apply Style A
    "then next style."
    Now all paragraphs will be alternating -- style A, style B, style A, etc.
    Now do what I wrote initially, and you'll have pairs of paragraph in
    separate text frames.

  • Button to change bg-color in JTable cell

    Hello!
    I would like to change the background color of a cell with a klick on a button.
    There will be 3 colors, and the selected cell are the only one thats going to change.
    How do I do that?
    Heres my code:
    import javax.swing.*;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Rectangle;
    import javax.swing.JButton;
    import javax.swing.table.TableCellRenderer;
    import javax.swing.table.TableColumn;
    import javax.swing.table.TableColumnModel;
    import javax.swing.table.TableModel;
    public class Kinna extends JFrame {
         private static final long serialVersionUID = 1L;
         private JPanel jContentPane = null;
         private JTabbedPane jTabbedPane = null;
         private JScrollPane jScrollPane = null;
         private JTable jTable = null;
         private JButton jButtonRed = null;
         private JButton jButtonGreen = null;
         private JButton jButtonBlue = null;
         private JButton jButtonNewWeek = null;
         private JButton jButtonDelWeek = null;
          * This method initializes jTabbedPane     
          * @return javax.swing.JTabbedPane     
         private JTabbedPane getJTabbedPane() {
              if (jTabbedPane == null) {
                   jTabbedPane = new JTabbedPane();
                   jTabbedPane.setBounds(new Rectangle(105, 45, 545, 488));
                   jTabbedPane.addTab(null, null, getJScrollPane(), null);
              return jTabbedPane;
          * This method initializes jScrollPane     
          * @return javax.swing.JScrollPane     
         private JScrollPane getJScrollPane() {
              if (jScrollPane == null) {
                   jScrollPane = new JScrollPane();
                   jScrollPane.setViewportView(getJTable());
              return jScrollPane;
          * This method initializes jTable     
          * @return javax.swing.JTable     
         private JTable getJTable() {
              if (jTable == null) {
                   Object[] head = {"Namn", "M�ndag", "Tisdag", "Onsdag", "Torsdag", "Fredag"};
                   Object[][] data = {{"Niklas", "9-15", "9-15", "9-15", "9-15","9-15"},
                                            {"Niklas", "9-15", "9-15", "9-15", "9-15","9-15"}};
                   jTable = new JTable(data, head);
                      // This table shades every other column yellow
              return jTable;
          * This method initializes jButtonRed     
          * @return javax.swing.JButton     
         private JButton getJButtonRed() {
              if (jButtonRed == null) {
                   jButtonRed = new JButton("R�d");
                   jButtonRed.setBounds(new Rectangle(15, 30, 76, 31));
                   jButtonRed.setText("R�d");
                   jButtonRed.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
              return jButtonRed;
          * This method initializes jButtonGreen     
          * @return javax.swing.JButton     
         private JButton getJButtonGreen() {
              if (jButtonGreen == null) {
                   jButtonGreen = new JButton("R�d");
                   jButtonGreen.setBounds(new Rectangle(15, 75, 76, 31));
                   jButtonGreen.setText("Gr�n");
              return jButtonGreen;
          * This method initializes jButtonBlue     
          * @return javax.swing.JButton     
         private JButton getJButtonBlue() {
              if (jButtonBlue == null) {
                   jButtonBlue = new JButton("R�d");
                   jButtonBlue.setBounds(new Rectangle(15, 120, 76, 31));
                   jButtonBlue.setText("Bl�");
              return jButtonBlue;
          * This method initializes jButtonNewWeek     
          * @return javax.swing.JButton     
         private JButton getJButtonNewWeek() {
              if (jButtonNewWeek == null) {
                   jButtonNewWeek = new JButton();
                   jButtonNewWeek.setBounds(new Rectangle(270, 0, 91, 31));
                   jButtonNewWeek.setText("Ny Vecka");
                   jButtonNewWeek.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                             System.out.println("actionPerformed()");
                             int i = getJTabbedPane().getSelectedIndex() + 1;
                             String tab = "Index: " + i;
                             getJTabbedPane().addTab(tab, new JLabel("Hello"));
                             getJTabbedPane().setSelectedIndex(getJTabbedPane().getTabCount()-1);
              return jButtonNewWeek;
          * This method initializes jButtonDelWeek     
          * @return javax.swing.JButton     
         private JButton getJButtonDelWeek() {
              if (jButtonDelWeek == null) {
                   jButtonDelWeek = new JButton();
                   jButtonDelWeek.setBounds(new Rectangle(375, 0, 121, 31));
                   jButtonDelWeek.setText("Ta bort vecka");
                   jButtonDelWeek.addActionListener(new java.awt.event.ActionListener() {
                        public void actionPerformed(java.awt.event.ActionEvent e) {
                             System.out.println("actionPerformed()");
                             getJTabbedPane().removeTabAt(getJTabbedPane().getSelectedIndex());
              return jButtonDelWeek;
          * @param args
         public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        Kinna thisClass = new Kinna();
                        thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                        thisClass.setVisible(true);
          * This is the default constructor
         public Kinna() {
              super();
              initialize();
          * This method initializes this
          * @return void
         private void initialize() {
              this.setSize(670, 580);
              this.setContentPane(getJContentPane());
              this.setTitle("JFrame");
          * This method initializes jContentPane
          * @return javax.swing.JPanel
         private JPanel getJContentPane() {
              if (jContentPane == null) {
                   jContentPane = new JPanel();
                   jContentPane.setLayout(null);
                   jContentPane.add(getJTabbedPane(), null);
                   jContentPane.add(getJButtonRed(), null);
                   jContentPane.add(getJButtonGreen(), null);
                   jContentPane.add(getJButtonBlue(), null);
                   jContentPane.add(getJButtonNewWeek(), null);
                   jContentPane.add(getJButtonDelWeek(), null);
              return jContentPane;
    }  //  @jve:decl-index=0:visual-constraint="29,25"

    If you have a different color for every cell in the table, then maybe it would be easier to store a custom Object in the TableModel that has two pieces of information:
    a) the text to be displayed
    b) the background color of the text.
    Then you can write a custom renderer that uses both pieces of information to renderer the cell correctly.
    Here is an untested example of what the custom renderer might look like:
    class ColorRenderer extends DefaultTableCellRenderer
         public Component getTableCellRendererComponent(
                   JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
              super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
              CustomObject custom = (CustomObject)value;
              setText( custom.getText() );
              if (!isSelected)
                   setBackground( custom.getBackground() );
              return this;
    }

  • Coloring column in an ALV tree

    Hi all,
    What I want to do is set background color for columns in a tree-view ALV(class cl_gui_alv_tree). However no matter how I set the field EMPHASIZE in the fieldcatalog internal table, the display of the ALV tree keeps unchange. Anyone can help me on this?
    Thanks,
    Chen Chang

    Hi,
    <b>If u want to change the node colr in ALV tree do as follows</b>
    Adding Root Nodes for the tree.
    Key:
    NODE_KEY, RELATKEY, RELATSHIP, HIDDEN, DISABLED, ISFOLDER, N_IMAGE,
    EXP_IMAGE, <b>STYLE</b>, LAST_HITEM, NO_BRANCH, EXPANDER, DRAGDROPID, TEXT
      perform f9101_node_list using: '1' 'ROOT' '' '' '' c_x '' '' '' '' ''
                              c_x '' text-003.
    Adding subitems for the root node.
      perform f9101_node_list using:
                            Material Details
                              'MATRL' '1' '' '' '' '' '' '' '' '' '' '' ''
                              text-001,
                            Document Details
                              'DOCU' '1' '' '' '' '' '' '' '' '' '' '' ''
                              text-002.
    form f9101_node_list using    value(pnodekey)
                                 value(prelatkey)
                                 value(prelatship)
                                 value(phidden)
                                 value(pdisabled)
                                 value(pisfolder)
                                 value(pimage)
                                 value(pexpimage)
                                 value(pstyle)
                                 value(plastitem)
                                 value(pnobranch)
                                 value(pexpander)
                                 value(pdragdropid)
                                 value(ptext).
      w_nodes-node_key   = pnodekey.
      w_nodes-relatkey   = prelatkey.
      w_nodes-relatship  = prelatship. "Natural number
      w_nodes-hidden     = phidden.
      w_nodes-disabled   = pdisabled.
      w_nodes-isfolder   = pisfolder.
      w_nodes-n_image    =  pimage.  "Icons / embedded bitmap
      w_nodes-exp_image  = pexpimage. "Icons / embedded bitmap
    <b>  w_nodes-style      = pstyle.</b>  w_nodes-last_hitem = plastitem. "Tree Control: Column Name / Item
      "Name
      w_nodes-no_branch  = pnobranch.
      w_nodes-expander   = pexpander.
      w_nodes-dragdropid = pdragdropid.
      w_nodes-text       = ptext.
      append w_nodes to i_nodes.
    endform.                    " f9101_node_list
    Try changing the style so that u can change the column color.
    If u want that in ALV grid
    1. different color in line of alv
    2. Coloring Cells/rows in ALV Grid.
    Got this from forum
    report .
    Use of colours in ALV grid (cell, line and column) *
    Table
    tables : mara.
    Type
    types : begin of ty_mara,
    matnr like mara-matnr,
    matkl like mara-matkl,
    counter(4) type n,
    free_text(15) type c,
    color_line(4) type c, " Line color
    color_cell type lvc_t_scol, " Cell color
    end of ty_mara.
    Structures
    data : wa_mara type ty_mara,
    wa_fieldcat type lvc_s_fcat,
    is_layout type lvc_s_layo,
    wa_color type lvc_s_scol.
    Internal table
    data : it_mara type standard table of ty_mara,
    it_fieldcat type standard table of lvc_s_fcat,
    it_color type table of lvc_s_scol.
    Variables
    data : okcode like sy-ucomm,
    w_alv_grid type ref to cl_gui_alv_grid,
    w_docking_container type ref to cl_gui_docking_container.
    parameters : p_column as checkbox,
    p_line as checkbox,
    p_cell as checkbox.
    at selection-screen output.
    perform get_data.
    perform fill_catalog.
    if w_docking_container is initial.
    perform create_objects.
    endif.
    *& Form create_objects
    form create_objects.
    create object w_docking_container
    exporting
    ratio = 60
    exceptions
    cntl_error = 1
    cntl_system_error = 2
    create_error = 3
    lifetime_error = 4
    lifetime_dynpro_dynpro_link = 5
    others = 6.
    create object w_alv_grid
    exporting
    i_parent = w_docking_container.
    Field that identify color line in internal table
    move 'COLOR_LINE' to is_layout-info_fname.
    Field that identify cell color in inetrnal table
    move 'COLOR_CELL' to is_layout-ctab_fname.
    call method w_alv_grid->set_table_for_first_display
    exporting
    is_layout = is_layout
    changing
    it_outtab = it_mara
    it_fieldcatalog = it_fieldcat
    exceptions
    invalid_parameter_combination = 1
    program_error = 2
    too_many_lines = 3
    others = 4.
    endform.
    *& Form get_data
    form get_data.
    select * from mara up to 5 rows.
    clear : wa_mara-color_line, wa_mara-color_cell.
    move-corresponding mara to wa_mara.
    add 1 to wa_mara-counter.
    move 'Blabla' to wa_mara-free_text.
    if wa_mara-counter = '0002'
    and p_line = 'X'.
    Color line move 'C410' to wa_mara-color_line.
    elseif wa_mara-counter = '0004'
    and p_cell = 'X'.
    Color cell
    move 'FREE_TEXT' to wa_color-fname.
    move '6' to wa_color-color-col.
    move '1' to wa_color-color-int.
    move '1' to wa_color-color-inv.
    append wa_color to it_color.
    wa_mara-color_cell[] = it_color[].
    endif.
    append wa_mara to it_mara.
    endselect.
    endform.
    *& Form fill_catalog
    form fill_catalog.
    Colour code : *
    Colour is a 4-char field where : *
    - 1st char = C (color property) *
    - 2nd char = color code (from 0 to 7) *
    0 = background color *
    1 = blue *
    2 = gray *
    3 = yellow *
    4 = blue/gray *
    5 = green *
    6 = red *
    7 = orange *
    - 3rd char = intensified (0=off, 1=on) *
    - 4th char = inverse display (0=off, 1=on) *
    Colour overwriting priority : *
    1. Line *
    2. Cell *
    3. Column *
    data : w_position type i value '1'.
    clear wa_fieldcat.
    move w_position to wa_fieldcat-col_pos.
    move 'MATNR' to wa_fieldcat-fieldname.
    move 'MARA' to wa_fieldcat-ref_table.
    move 'MATNR' to wa_fieldcat-ref_field.
    append wa_fieldcat to it_fieldcat.
    add 1 to w_position.
    clear wa_fieldcat.
    move w_position to wa_fieldcat-col_pos.
    move 'MATKL' to wa_fieldcat-fieldname.
    move 'MARA' to wa_fieldcat-ref_table.
    move 'MATKL' to wa_fieldcat-ref_field.
    Color column
    if p_column = 'X'.
    move 'C610' to wa_fieldcat-emphasize.
    endif.
    append wa_fieldcat to it_fieldcat.
    add 1 to w_position.
    clear wa_fieldcat.
    move w_position to wa_fieldcat-col_pos.
    move 'COUNTER' to wa_fieldcat-fieldname.
    move 'N' to wa_fieldcat-inttype.
    move '4' to wa_fieldcat-intlen.
    move 'Counter' to wa_fieldcat-coltext.
    append wa_fieldcat to it_fieldcat.
    add 1 to w_position.
    clear wa_fieldcat.
    move w_position to wa_fieldcat-col_pos.
    move 'FREE_TEXT' to wa_fieldcat-fieldname.
    move 'C' to wa_fieldcat-inttype.
    move '20' to wa_fieldcat-intlen.
    move 'Text' to wa_fieldcat-coltext.
    append wa_fieldcat to it_fieldcat.
    endform.
    Check this link to get code for different colors http://www.sapdesignguild.org/resources/ma_guidelines/VisualDesignRules/colors.html
    Try this out the same thing will work for Reuse also.
    Thanks & Regards,
    Judith.
    Message was edited by: Judith Jessie Selvi

  • Alternating text color of excel cell items after each space?

    Hello. I have a script that emails a table of info which works fine and that looks like this:
    name, samaccountname, date, memberof
    In the email table I was able to have it do a line break on each space so that the memberof groups are on on separate lines for easier reading.
    Well I've been wanting to send the data to store in a csv sheet as well. I can get it going in there but for the member of column it puts in memberof1  memberof2  memberof3 etc etc on one line. The CNs OUs etc are all removed and its just the group
    names separated by spaces. Works but a little hard to read.
    I was thinking maybe there was a way to open the excel file for writing and on that one column have it alternate text colors using the space as the delimiter? Everything would be easier to read that way. Is this possible ?
    Thanks

    Thanks. I did look at that and have this so far. Im  just trying to echo it out right now, but Im guessing that somehow in the foreach ($item in $groups) I need to create an array or something? Then Id want to apply one color to each item in the array.
    Ive tried several different combinations and was trying $item.spli(" ") but it always comes back looking the same.
    So right now $item echos like this
    Group1  Group2  Group3  Group4  Group5
    Id just want to alternate each space delimited item one of two colors. Then take those appened colors of each item and write it back to the cell that I read it from in the column so that its easier to read. Is this even possible?
    $objExcel = new-object -comobject excel.application 
    $objExcel.Visible = $True
    $ExcelFilesLocation = "c:\"
    $UserWorkBook = $objExcel.Workbooks.Open($ExcelFilesLocation + "groups.csv")
    $UserWorksheet = $UserWorkBook.Worksheets.Item(1)
    $intRow = 2
    Do {
     # Reading the first column of the current row
     $groups = $UserWorksheet.Cells.Item($intRow, 4).Value()
     foreach ($item in $groups)
     $regex = [regex] "\s"
     $split = $regex.split($item)
     Write-Host $split
     # Move to next row
     $intRow++
     While ($UserWorksheet.Cells.Item($intRow,1).Value() -ne $null)

  • HOw can i change the color of a cell

    How can I change the color of a cell when it is selected. I select the cell by pressing enter, then I want the text in the cell to change color to red, but all the cells in the table change color. Please I would be grateful for some help

    Subclass DefaultTableCellRenderer.
    public class MyCellRenderer extends DefaultTableCellRenderer
    Override
    public Componet getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
    JLabel lab = new JLabel(String)value);
    lab.setOpaque(true);
    return lab;
    if(isSelected)
    lab.setBackground(Color.red);
    else
    lab.setBackground(Color.white);
    Set the columns in your table:
    table.getCoulumModel.getColumn(0).setCellRenderer(new myCellRenderer());
    table.getCoulumModel.getColumn(1).setCellRenderer(new myCellRenderer());
    etc. for each column in your table.

  • How to change the Background color of a cell in JTable

    hi!
    Actually i want to change the background color of few cells in JTable
    is there any method to make this change in JTable ?
    and also is it possible to have 5 rows with single column and 5 rows with 3 columns in a single JTable

    i want to change the background color of few cells in JTableDepending on your requirements for the coloring of cells it may be easier to override the prepareRenderer() method of JTable:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=610474

  • How to change the background color of a cell in datagrid using flex3

    i want to change the background color of a cell.....how can i achieve this.....and also i want to know how a spacing cane be done between cells in a datagrid...plzzz help me???

    The only way I can see to do this is to use an item renderer for your cells.  This is really scruffy and would need tyding up, and maybe with a little more time could do better or someone else may have an idea but none the less this works.
    Define a custom component as below;
    This has logic to see what the value of the data is proveided by the dataprovider for the row, and if it matches the conditions in this case is equal to 5 sets the background color.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="88" height="26" dataChange="doColor()" borderColor="#000000" borderStyle="solid"
        backgroundAlpha="1">
        <mx:Script>
            <![CDATA[
                private function doColor():void {
                    if (data.value == 5) {
                        setStyle('backgroundColor', 0xcccccc);
                    } else {
                        setStyle('backgroundColor', 0xffffff);
            ]]>
        </mx:Script>
    </mx:Canvas>
    Now just apply the item renderer in the datagrid and that will do it.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"  xmlns:ns1="*">
        <mx:Script>
            <![CDATA[
                import mx.collections.ArrayCollection;
                [Bindable]
                private var ac:ArrayCollection = new ArrayCollection([
                    {value : 1},
                    {value : 2},
                    {value : 3},
                    {value : 4},
                    {value : 5},
                    {value : 6},
                    {value : 7},
                    {value : 8},
                    {value : 9},
                    {value : 10}
          ]]>
        </mx:Script>
        <mx:DataGrid x="40" y="36" width="408" height="193" dataProvider="{ac}">
            <mx:columns>
                <mx:DataGridColumn headerText="Column 1" dataField="value" itemRenderer="MyComp"/>
                <mx:DataGridColumn headerText="Column 2" dataField="col2"/>
                <mx:DataGridColumn headerText="Column 3" dataField="col3"/>
            </mx:columns>
        </mx:DataGrid>
    </mx:Application>
    I hope this helps
    Andrew

  • Change the background color of a cell in JTable

    Hi all,
    How can I change the background color of individual cell in JTable. I need to construct my own TableCellRenderer or not? I'm now using the DefaultTableCellRenderer now.
    Thx

    You could create your own renderer or you could try something like:
    table = new JTable(model)
         public TableCellRenderer getCellRenderer(int row, int column)
              DefaultTableCellRenderer tcr =
               (DefaultTableCellRenderer)super.getCellRenderer(row, column);
              if (row == 1 && column == 1)
                   tcr.setBackground(Color.green);
              else
                   tcr.setBackground(Color.red);
              return tcr;
    };

  • How do i change the cell color of each cell in datagrid dynamically

    I have a  datagrid filled in with data..My job is to change the cell color of a particular cell in the datagrid when the user clicks that cell..Please help me asap..I have to change the color of each cell dynamically..

    Pls find the solution of ur problem.Let me know if you have any issue.
    MainApplicaion.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical">
        <mx:Script>
            <![CDATA[
                import mx.collections.ArrayCollection;
                import mx.events.ListEvent;
                [Bindable]
                  private var listDataArrayCollection:ArrayCollection=
                  new ArrayCollection([
                    {seq:'1',color:'0xFF0000', names:'John'},
                    {seq:'2',color:'0x00FF00', names:'Alex'},
                    {seq:'3',color:'0x0000FF', names:'Peter'},
                    {seq:'4',color:'0xFF0000', names:'Sam'},
                    {seq:'5',color:'0x00FF00', names:'Alis'},
                    {seq:'6',color:'0x0000FF', names:'Robin'},
                    {seq:'7',color:'0xFF0000', names:'Mark'},
                    {seq:'8',color:'0x00FF00', names:'Steave'},
                    {seq:'9',color:'0x0000FF', names:'Fill'},
                    {seq:'10',color:'0xFF0000', names:'Abraham'},
                    {seq:'11',color:'0x00FF00', names:'Hennery'},
                    {seq:'12',color:'0x0000FF', names:'Luis'},
                    {seq:'13',color:'0xFF0000', names:'Herry'},
                    {seq:'14',color:'0x00FF00', names:'Markus'},
                    {seq:'15',color:'0x0000FF', names:'Flip'},
                    {seq:'16',color:'0xFF0000', names:'John_1'},
                    {seq:'17',color:'0x00FF00', names:'Alex_1'},
                    {seq:'18',color:'0x0000FF', names:'Peter_1'},
                    {seq:'19',color:'0xFF0000', names:'Sam_1'},
                    {seq:'20',color:'0x00FF00', names:'Alis_1'},
                    {seq:'21',color:'0x0000FF', names:'Robin_1'},
                    {seq:'22',color:'0xFF0000', names:'Mark_1'},
                    {seq:'23',color:'0x00FF00', names:'Steave_1'},
                    {seq:'24',color:'0x0000FF', names:'Fill_1'},
                    {seq:'25',color:'0xFF0000', names:'Abraham_1'},
                    {seq:'26',color:'0x00FF00', names:'Hennery_1'},
                    {seq:'27',color:'0x0000FF', names:'Luis_1'},
                    {seq:'28',color:'0xFF0000', names:'Herry_1'},
                    {seq:'29',color:'0x00FF00', names:'Markus_1'},
                    {seq:'30',color:'0x0000FF', names:'Flip_2'}
                private function onItemClick(event : ListEvent):void
                    var dataObj : Object = event.itemRenderer.data;
                    dataObj.color = "0xFF00FF";
                    event.itemRenderer.data = dataObj;
            ]]>
        </mx:Script>
        <mx:VBox width="300" height="100%"
            horizontalAlign="center"
            verticalAlign="middle">
            <mx:DataGrid id="listComponent" width="50%"
                     height="100%"
                     borderStyle="none"
                     dataProvider="{listDataArrayCollection}"
                     itemClick="onItemClick(event)">
                     <mx:columns>
                     <mx:DataGridColumn width="100" dataField="{data.seq}" headerText="Seq" itemRenderer="SeqItemRenderer" />
                     <mx:DataGridColumn width="100" dataField="{data.names}" headerText="Name" itemRenderer="NameItemRenderer"/>
                     </mx:columns>
                     </mx:DataGrid>
        </mx:VBox>
    </mx:Application
    NameItemRenderer.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"
        width="100" height="30" horizontalGap="5" horizontalScrollPolicy="off">
    <mx:Script>
        <![CDATA[
            override public function set data(value:Object):void
                 super.data = value;
        ]]>
    </mx:Script>
            <mx:TextInput width="75" height="30"
                 text="{data.names}"
                 editable="false" backgroundColor="{data.color}"/>
        </mx:HBox>
    SeqItemRenderer.mxml
    <?xml version="1.0" encoding="utf-8"?>
    <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml"
        width="100" height="30" horizontalGap="5" horizontalScrollPolicy="off">
    <mx:Script>
        <![CDATA[
            override public function set data(value:Object):void
                 super.data = value;
        ]]>
    </mx:Script>
            <mx:TextInput width="75" height="30"
                 text="{data.seq}"
                 editable="false" backgroundColor="{data.color}"/>
        </mx:HBox>
    with Regards,
    Shardul Singh Bartwal

Maybe you are looking for

  • How can I reformat my old mac air, since I have the new one

    How can I reformat my old mac_book_air, since I have the new one?

  • How to load a data file? help!

    I am developing a bean for JSF and JSP. my directory is like this WEB-INF classes wol woldss.class /data hh.txt in woldss.java, i would like to load hh.txt file. my code: private String fname= "/data/hh.txt"; URL url = this.getClass().getResource(fna

  • Is it possible to use a MacBook Pro 9.1 with Snow Leopard

    Hallo, i tryed out to install a macbook pro 9,1 with Snow Leopard, but by loading the drivers he stops with booting. The version i try out is 10.6.8 and i tryed to boot from an extern drive also with 10.6.8 with the newest updates. I hope to get some

  • Backup Apple Mail

    Hello! Lately I have been going through quite some trouble while I was trying to set up rules for my 3 IMAP mail accounts in Mail.app. I'm still not sure everything works as it's supposed to, so I'd like to create a full backup of all my emails. Does

  • Elements 9 Freezes on Adding Canon DSLR video files

    I just purchased Premiere Elements 9 to edit my Canon T2i video files.  When I try to add the video files by going to Get Media - From File, the progress bar pops up and goes away quickly like it is finished processing the addition to my organizer, b