Custom StyledEditorKit: simple example/tutorial?

I'm trying to write a simple EditorKit to color specific parts of a text (and later different fonts). I extended StyledEditorKit for this, but can't get any text to be colored in my JTextPane. The Java Tutorial and also what I've found in this forum and google didn't show how to start writing a simple EditorKit.

Well, I have a simple example that shows how to start. Of course it's brute force colorizing always the complete text and only works for well-formed XML, but it's a working example of how to write your own EditorKit. It shows that only a few things have to be done.
public class XMLEditorKit extends StyledEditorKit {
     * Constructor.
    public XMLEditorKit() {
        super();
    }//XMLEditorKit()
     * Overwrites super.
    public String getContentType() {
        return "text/xml";
    }//getContentType()
     * Overwrites super.
    public Document createDefaultDocument() {
        return new XMLDocument();
    }//createDefaultDocument()
}//XMLEditorKit
class XMLDocument extends DefaultStyledDocument {
    /** Attributes for XML element tag. */
    private MutableAttributeSet tag = null;
    /** Attributes for element value. */
    private MutableAttributeSet elementValue = null;
     * Constructor.
    public XMLDocument() {
        tag = new SimpleAttributeSet();
        StyleConstants.setForeground(tag, Color.blue);
        elementValue = new SimpleAttributeSet();
        StyleConstants.setForeground(elementValue, Color.black);
    }//XMLDocument()
     * Override AbstractDocument.
    public void insertString(int offset, String str, AttributeSet a) throws BadLocationException {
        super.insertString(offset, str, a);
        colorize();
    }//insertString()
     * Override AbstractDocument.
    public void remove(int offset, int length) throws BadLocationException {
        super.remove(offset, length);
        colorize();
    }//remove()
     * Called when document content changed to revalidate syntax highlightning.
     * Only works correctly for well-formed XML.
    private void colorize() throws BadLocationException {
        String text = getText(0, getLength());
        int startIndex = 0;
        int endIndex = text.length() + 1;
        int openIndex = 0;
        int closeIndex = 0;
        boolean outOfTag = true;
        while (startIndex <= endIndex) {
            openIndex  = text.indexOf('<', startIndex); //next '<'
            closeIndex = text.indexOf('>', startIndex); //next '>'
            if (outOfTag) {
                if (openIndex >= 0) {
                    setCharacterAttributes(startIndex, openIndex - startIndex, elementValue, false);
                    startIndex = openIndex;
                    outOfTag = false;
                } else {
                    setCharacterAttributes(startIndex, endIndex + 1, elementValue, false);
                    break;
            } else { //withinTag
                if (closeIndex >= 0) {                       
                    setCharacterAttributes(startIndex, closeIndex - startIndex + 1, tag, false);
                    startIndex = closeIndex + 1;
                    outOfTag = true;
                } else {
                    setCharacterAttributes(startIndex, endIndex + 1, tag, false);
                    break;
            }//next occurence
    }//colorize()
}//XMLDocumentSo, to start write a custom EditorKit,
1. extend StyledEditorKit (or DefaultEditorKit, if you like)
2. create a document class extending DefaultStyledDocument
3. overwrite insertString()/remove() in your document class to implement your custom text styling.

Similar Messages

  • Trying to create a simple example. Need Help!

    I'm trying to create a very simlpe examlpe using Swing components to illustrate a MVC architecture.
    I have a JFrame containing a JTree and a JButton.
    What I'd like to happen is when I click the JButton the JTree model is changed in some fashion and the the view is refreshed due to the models change.
    If anyone out there has a simple example of any MVC architecture involving Swing components I'd love to see it.
    Thx

    Sure, look at any of the Sun tutorials. For example, look in your API documentation for JTree; it has a link to a tutorial about how to use JTree.

  • Simple example of chat

    I am needing a simple example of chat made with spry…
    using an archive xml I am not obtaining to bring up to date the
    messages!

    You can do it with a $1000 dollar server, and much much much more, just not Adobe's $1000 dollar "server".
    I would have to say that I have yet to come across even one client that wasn't completely pissed off when they bought the streaming version and realized how little it does. I can't even imagine how many support calls have gone in to Adobe for either a full refund or an upgrade to a now extremely disgruntled customer. It's a shame, gives FMS and Adobe a bit of a bad name despite the amazing product FMIS is.

  • Simple example of alv report.

    hi.
    can anyone have simple example of ALV report?

    Hi Puru,
    Check out this simple ALV report,
    TABLES : vbak,vbap.
    TYPE-POOLS : slis.
    DATA:  repid                LIKE sy-repid,                             "Report ID
               is_layout            TYPE slis_layout_alv,                      "Layout For ALV
               it_fieldcat          TYPE slis_t_fieldcat_alv,                  "ITAB for field
               it_events            TYPE slis_t_event,                         "ITAB for event
               it_sub               TYPE slis_layout_alv_spec1,                "subtotals
               i_header             TYPE slis_t_listheader,                    "Itab for listheader
               lt_sort              TYPE  slis_t_sortinfo_alv,                 "itab for sorting
               wa_sort              LIKE LINE OF lt_sort."  slis_t_sortinfo_alv.
    DATA : BEGIN OF itab OCCURS 0,
                   vbeln LIKE vbak-vbeln,
                   erdat LIKE vbak-erdat,
                   kunag LIKE vbak-kunnr,
                  ernam LIKE vbak-ernam,
              END OF itab.
    DATA : BEGIN OF it_disp OCCURS 0,
                vbeln LIKE vbak-vbeln,
                erdat LIKE vbak-erdat,
                kunag LIKE vbak-kunnr,
                ernam LIKE vbak-ernam,
                posnr LIKE vbap-posnr,
                matnr LIKE vbap-matnr,
             END OF it_disp.
    ****selection-screen
    SELECTION-SCREEN BEGIN OF BLOCK b1.
    SELECT-OPTIONS : s_vbeln FOR vbak-vbeln,
                                   s_date FOR vbak-erdat.
    SELECTION-SCREEN END OF BLOCK b1.
    AT SELECTION-SCREEN.
    START-OF-SELECTION.
      PERFORM get_data.
      PERFORM modify_data.
      PERFORM disp_data  .
    END-OF-SELECTION.
    *&      Form  get_data
          text
    -->  p1        text
    <--  p2        text
    FORM get_data .
      SELECT avbeln aerdat akunnr aernam bposnr bmatnr
             INTO TABLE it_disp FROM vbak AS a
             INNER JOIN vbap AS b ON
             avbeln = bvbeln
             WHERE a~vbeln IN s_vbeln.
    ENDFORM.                    " get_data
    *&      Form  modify_data
          text
    -->  p1        text
    <--  p2        text
    FORM modify_data .
      MOVE-CORRESPONDING itab TO it_disp.
      APPEND it_disp.
      CLEAR it_disp.
    ENDFORM.                    " modify_data
    *&      Form  Disp_data
          text
    -->  p1        text
    <--  p2        text
    FORM disp_data .
      PERFORM fill_layout_structure.
      PERFORM fill_field_catalog_table.
      PERFORM alv_header USING i_header.
      PERFORM call_alv_function.
    ENDFORM.                    " Disp_data
    *&      Form  fill_layout_structure
          text
    -->  p1        text
    <--  p2        text
    FORM fill_layout_structure .
      CLEAR is_layout.
      is_layout-colwidth_optimize = 'X'.
      is_layout-zebra = 'X'.
      is_layout-no_input          = 'X'.
      is_layout-colwidth_optimize = 'X'.
      is_layout-totals_text       = 'Totals'(201).
      is_layout-totals_only        = 'X'.
      is_layout-zebra             = 'X'.
      is_layout-group_change_edit = 'X'.
      is_layout-header_text       = 'helllllo'.
    ENDFORM.                    " fill_layout_structure
    *&      Form  fill_field_catalog_table
          text
    -->  p1        text
    <--  p2        text
    FORM fill_field_catalog_table .
      DATA : gls1(10).
    BREAK-POINT.
      PERFORM fill_field_catalog  USING :
                      'VBELN'             'SALES DOC NO.'  '10'   'IT_FINAL' space    space    'C11'     ' '  ' ',
                      'ERDAT'             'DATE'           '40'   'IT_FINAL' space    space    'C11'     ' '  ' ',
                      'KUNAG'             'CUSTOMER'       '6'    'IT_FINAL' space    space    'C11'     'X '  ' ',
                      'ERNAM'             'NAME'           '20'   'IT_FINAL' space    space    'C11'     'X'  ' ',
                      'POSNR'             'ITEM'           '10'   'IT_FINAL' space    space    'C11'     ' '  ' ',
                      'MATNR'             'MATERIAL'       '20'   'IT_FINAL' space    space    'C11'     ' '  ' '.
    ENDFORM.                    " fill_field_catalog_table
    *&      Form  fill_field_catalog
          text
    FORM fill_field_catalog USING f d l t s z y a b.
      DATA t_fld TYPE slis_fieldcat_alv.
      STATICS pos LIKE sy-index VALUE 0.
      pos = pos + 1.
      CLEAR t_fld.
      MOVE 1 TO   t_fld-row_pos.
      MOVE pos TO t_fld-col_pos.
      MOVE f TO   t_fld-fieldname.
      MOVE d TO   t_fld-seltext_m.
      MOVE l TO   t_fld-outputlen.
      MOVE t TO   t_fld-tabname.
      MOVE s TO   t_fld-do_sum.
      MOVE z TO   t_fld-no_zero.
      MOVE y TO   t_fld-emphasize.
      MOVE a TO   t_fld-no_out.
      MOVE b TO   t_fld-no_sum.
      APPEND t_fld TO it_fieldcat.
    ENDFORM.                    " fill_field_catalog
    *&      Form  alv_header
          text
         -->P_I_HEADER  text
    FORM alv_header  USING    p_i_header.
      DATA: wa_line TYPE slis_listheader.
      CLEAR wa_line.
      wa_line-typ = 'H'.
      wa_line-info = 'Walvoil Fluid Power India Limited'.
      APPEND wa_line TO i_header.
    ENDFORM.                    " alv_header
    *&      Form  call_alv_function
          text
    -->  p1        text
    <--  p2        text
    FORM call_alv_function .
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
       I_CALLBACK_PROGRAM                = REPID
       I_CALLBACK_PF_STATUS_SET          = ' '
       IS_LAYOUT                         = IS_LAYOUT
       IT_FIELDCAT                       = IT_FIELDCAT
      TABLES
        t_outtab                          = IT_DISP.
    IF sy-subrc <> 0.
    ENDIF.
    ENDFORM.                    " call_alv_function
    reward it it useful to u,
    Best Wishes,
    regards
    Guna..

  • I need  a simple example of shopping cart(newbie)

    Has any one come across a simple example of shopping cart and the process
    behind it i.e. from jsp to ejb. So far I have looked at the buybeans example
    and it still is not clear the approach that was used.
    I would be greatful for any assistance thank you
    Kenneth A-Adjei

    Take a look at:
    http://java.sun.com/docs/books/tutorial/servlets/overview/example.html
    "Ken Adjei" <[email protected]> wrote in message
    news:3960a901$[email protected]..
    Has any one come across a simple example of shopping cart and the process
    behind it i.e. from jsp to ejb. So far I have looked at the buybeansexample
    and it still is not clear the approach that was used.
    I would be greatful for any assistance thank you
    Kenneth A-Adjei

  • Simple example code connect Ldap server...

    Hi all.
    I am beginning working with Ldap.
    Please help me a simple example source code to connect with Ldap server.
    I install Ldap administrator and see a public Server : ldap://directory.d-trust.de:389 How to connect it ?
    Thanks in advance
    Diego

    Hi ThuCT,
    Just have a read of the following links :
    http://www.javaworld.com/javaworld/jw-03-2000/jw-0324-ldap.html
    http://java.sun.com/products/jndi/tutorial/ldap/index.html

  • Can anyone plz send a simple example of interactive reports

    Hi gurus,
    Can anyone plz send a simple example of interactive reports using subscreenswhich contains at line-selection, at user-command, pf and other commands.
    Thanks in advance.

    Hi,
    * Macro definition
    DEFINE m_fieldcat.
      add 1 to ls_fieldcat-col_pos.
      ls_fieldcat-fieldname   = &1.
      ls_fieldcat-ref_tabname = &2.
      ls_fieldcat-cfieldname  = &3.
      ls_fieldcat-qfieldname  = &4.
      append ls_fieldcat to lt_fieldcat.
    END-OF-DEFINITION.
    TYPE-POOLS: slis.                      " ALV Global types
    TYPES:
      BEGIN OF ty_vbak,
        vkorg TYPE vbak-vkorg,             " Sales organization
        kunnr TYPE vbak-kunnr,             " Sold-to party
        vbeln TYPE vbak-vbeln,             " Sales document
        netwr TYPE vbak-netwr,             " Net Value of the Sales Order
        waerk TYPE vbak-waerk,             " Currency
      END OF ty_vbak,
      BEGIN OF ty_vbap,
        vbeln  TYPE vbap-vbeln,            " Sales document
        posnr  TYPE vbap-posnr,            " Sales document item
        matnr  TYPE vbap-matnr,            " Material number
        arktx  TYPE vbap-arktx,            " Short text for sales order item
        kwmeng TYPE vbap-kwmeng,           " Order quantity
        vrkme  TYPE vbap-vrkme,            " Quantity Unit
        netwr  TYPE vbap-netwr,            " Net value of the order item
        waerk  TYPE vbap-waerk,            " Currency
      END OF ty_vbap.
    DATA :
      gs_vbak TYPE ty_vbak,
    * Data displayed in the first list
      gt_vbak TYPE TABLE OF ty_vbak,
    * Data displayed in the second list
      gt_vbap TYPE TABLE OF ty_vbap.
    SELECT-OPTIONS :
      s_vkorg FOR gs_vbak-vkorg,           " Sales organization
      s_kunnr FOR gs_vbak-kunnr,           " Sold-to party
      s_vbeln FOR gs_vbak-vbeln.           " Sales document
    SELECTION-SCREEN :
      SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.    "#EC NEEDED
    PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    INITIALIZATION.
      v_1 = 'Maximum of records to read'.
    START-OF-SELECTION.
      PERFORM f_read_data_vbak.
      PERFORM f_display_data_vbak.
    *      Form  f_read_data_vbak
    FORM f_read_data_vbak.
      SELECT vkorg kunnr vbeln netwr waerk
        INTO CORRESPONDING FIELDS OF TABLE gt_vbak
          UP TO p_max ROWS
        FROM vbak
       WHERE kunnr IN s_kunnr
         AND vbeln IN s_vbeln
         AND vkorg IN s_vkorg
         and vbtyp = 'C'.                  " C = Sales Orders.
    ENDFORM.                               " F_READ_DATA_VBAK
    *      Form  f_display_data_vbak
    FORM f_display_data_vbak.
      DATA:
        ls_fieldcat TYPE slis_fieldcat_alv,
        lt_fieldcat TYPE slis_t_fieldcat_alv.
    * Build the field catalog
      m_fieldcat 'VKORG' 'VBAK' '' ''.
      m_fieldcat 'KUNNR' 'VBAK' '' ''.
      m_fieldcat 'VBELN' 'VBAK' ''  ''.
      m_fieldcat 'NETWR' 'VBAK' 'WAERK' ''.
      m_fieldcat 'WAERK' 'VBAK' ''  ''.
    * Display the first list
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program      = sy-cprog
          i_callback_user_command = 'USER_COMMAND'
          it_fieldcat             = lt_fieldcat
        TABLES
          t_outtab                = gt_vbak.
    ENDFORM.                               " F_DISPLAY_DATA_VBAK
    *       FORM USER_COMMAND                                             *
    FORM user_command USING u_ucomm     TYPE syucomm
                            us_selfield TYPE slis_selfield.     "#EC CALLED
      CASE u_ucomm.
        WHEN '&IC1'.
          READ TABLE gt_vbak INDEX us_selfield-tabindex INTO gs_vbak.
          CHECK sy-subrc EQ 0.
          PERFORM f_read_data_vbap.        " Read data from VBAP
          PERFORM f_display_data_vbap.
      ENDCASE.
    ENDFORM.                               " USER_COMMAND
    *      Form  f_read_data_vbap
    FORM f_read_data_vbap.
      SELECT vbeln posnr matnr arktx kwmeng vrkme netwr waerk
        INTO CORRESPONDING FIELDS OF TABLE gt_vbap
        FROM vbap
       WHERE vbeln = gs_vbak-vbeln.
    ENDFORM.                               " F_READ_DATA_VBAP
    *      Form  f_display_data_vbap
    FORM f_display_data_vbap.
      DATA:
        ls_fieldcat TYPE slis_fieldcat_alv,
        lt_fieldcat TYPE slis_t_fieldcat_alv.
    * Build the field catalog
      m_fieldcat 'VBELN'  'VBAP' '' ''.
      m_fieldcat 'POSNR'  'VBAP' '' ''.
      m_fieldcat 'MATNR'  'VBAP' '' ''.
      m_fieldcat 'ARKTX'  'VBAP' '' ''.
      m_fieldcat 'KWMENG' 'VBAP' '' 'VRKME'.
      m_fieldcat 'VRKME'  'VBAP' '' ''.
      m_fieldcat 'NETWR'  'VBAP' 'WAERK' ''.
      m_fieldcat 'WAERK'  'VBAP' '' ''.
    * Display the second list
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          it_fieldcat = lt_fieldcat
        TABLES
          t_outtab    = gt_vbap.
    ENDFORM.                               " F_DISPLAY_DATA_VBAP
    2nd example
    * Macro definition
    DEFINE m_fieldcat.
      add 1 to ls_fieldcat-col_pos.
      ls_fieldcat-fieldname   = &1.
      ls_fieldcat-ref_tabname = &2.
      append ls_fieldcat to lt_fieldcat.
    END-OF-DEFINITION.
    TYPE-POOLS: slis.                      " ALV Global types
    SELECTION-SCREEN :
      SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.    "#EC NEEDED
    PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.
    SELECTION-SCREEN END OF LINE.
    TYPES:
    * Data displayed in the first list
      BEGIN OF ty_kna1,
        kunnr TYPE kna1-kunnr,             " Customer number
        name1 TYPE kna1-name1,             " Customer name
        ort01 TYPE kna1-ort01,             " Customer city
      END OF ty_kna1,
    * Data displayed in the second list
      BEGIN OF ty_vbak,
        vkorg TYPE vbak-vkorg,             " Sales organization
        kunnr TYPE vbak-kunnr,             " Sold-to party
        vbeln TYPE vbak-vbeln,             " Sales document
        netwr TYPE vbak-netwr,             " Net Value of the Sales Order
      END OF ty_vbak,
    * Data displayed in the third list
      BEGIN OF ty_vbap,
        vbeln  TYPE vbap-vbeln,            " Sales document
        posnr  TYPE vbap-posnr,            " Sales document item
        matnr  TYPE vbap-matnr,            " Material number
        arktx  TYPE vbap-arktx,            " Short text for sales order item
        kwmeng TYPE vbap-kwmeng,           " Order quantity
        netwr  TYPE vbap-netwr,            " Net value of the order item
      END OF ty_vbap.
    DATA:
      gs_kna1 TYPE ty_kna1,
      gt_kna1 TYPE TABLE OF ty_kna1,
      gs_vbak TYPE ty_vbak,
      gt_vbak TYPE TABLE OF ty_vbak,
      gt_vbap TYPE TABLE OF ty_vbap.
    INITIALIZATION.
      v_1 = 'Maximum of records to read'.
    START-OF-SELECTION.
      PERFORM f_read_data_kna1.
    END-OF-SELECTION.
      PERFORM f_display_data_kna1.
    *      Form  f_read_data_kna1
    FORM f_read_data_kna1.
    * Read customer data with a least one order
      SELECT kunnr name1 ort01 INTO TABLE gt_kna1
               FROM kna1 AS k
                 UP TO p_max ROWS
              WHERE EXISTS
           ( SELECT kunnr FROM vbak WHERE kunnr = k~kunnr ).
    ENDFORM.                               " F_READ_DATA_KNA1
    *      Form  f_display_data_kna1
    FORM f_display_data_kna1.
      DATA:
        ls_fieldcat TYPE slis_fieldcat_alv,
        lt_fieldcat TYPE slis_t_fieldcat_alv.
    * Build the field catalog
      m_fieldcat 'KUNNR' 'KNA1'.
      m_fieldcat 'NAME1' 'KNA1'.
      m_fieldcat 'ORT01' 'KNA1'.
    * Display the first list
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program      = sy-cprog
          i_callback_user_command = 'USER_COMMAND_KNA1'
          it_fieldcat             = lt_fieldcat
        TABLES
          t_outtab                = gt_kna1.
    ENDFORM.                               " F_DISPLAY_DATA_KNA1
    *       FORM USER_COMMAND_KNA1                                        *
    FORM user_command_kna1 USING u_ucomm     TYPE sy-ucomm
                                 us_selfield TYPE slis_selfield."#EC CALLED
      CASE u_ucomm.
        WHEN '&IC1'.
          READ TABLE gt_kna1 INDEX us_selfield-tabindex INTO gs_kna1.
          CHECK sy-subrc EQ 0.
          PERFORM f_read_data_vbak.        " Read data from VBAK
          PERFORM f_display_data_vbak.     " Display orders
      ENDCASE.
    ENDFORM.                               " USER_COMMAND_KNA1
    *      Form  f_read_data_vbak
    FORM f_read_data_vbak.
      SELECT vkorg kunnr vbeln netwr
        INTO TABLE gt_vbak
        FROM vbak
          UP TO p_max ROWS
       WHERE kunnr = gs_kna1-kunnr.
    ENDFORM.                               " F_READ_DATA_VBAK
    *      Form  f_display_data_vbak
    FORM f_display_data_vbak.
      DATA:
        ls_fieldcat TYPE slis_fieldcat_alv,
        lt_fieldcat TYPE slis_t_fieldcat_alv.
    * Build the field catalog
      m_fieldcat 'VKORG' 'VBAK'.
      m_fieldcat 'KUNNR' 'VBAK'.
      m_fieldcat 'VBELN' 'VBAK'.
      m_fieldcat 'NETWR' 'VBAK'.
    * Display the second list
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          i_callback_program      = sy-cprog
          i_callback_user_command = 'USER_COMMAND_VBAK'
          it_fieldcat             = lt_fieldcat
        TABLES
          t_outtab                = gt_vbak.
    ENDFORM.                               " F_DISPLAY_DATA_VBAK
    *       FORM USER_COMMAND_VBAK                                        *
    FORM user_command_vbak USING u_ucomm     TYPE sy-ucomm
                                 us_selfield TYPE slis_selfield."#EC CALLED
      CASE u_ucomm.
        WHEN '&IC1'.
          READ TABLE gt_vbak INDEX us_selfield-tabindex INTO gs_vbak.
          CHECK sy-subrc EQ 0.
          PERFORM f_read_data_vbap.        " Read data from VBAP
          PERFORM f_display_data_vbap.     " Display items
      ENDCASE.
    ENDFORM.                               " USER_COMMAND_VBAK
    *      Form  f_read_data_vbap
    FORM f_read_data_vbap.
      SELECT vbeln posnr matnr arktx kwmeng netwr
        INTO TABLE gt_vbap
        FROM vbap
       WHERE vbeln = gs_vbak-vbeln.
    ENDFORM.                               " F_READ_DATA_VBAP
    *      Form  f_display_data_vbap
    FORM f_display_data_vbap.
      DATA:
        ls_fieldcat TYPE slis_fieldcat_alv,
        lt_fieldcat TYPE slis_t_fieldcat_alv.
    * Build the field catalog
      m_fieldcat 'VBELN'  'VBAP'.
      m_fieldcat 'POSNR'  'VBAP'.
      m_fieldcat 'MATNR'  'VBAP'.
      m_fieldcat 'ARKTX'  'VBAP'.
      m_fieldcat 'KWMENG' 'VBAP'.
      m_fieldcat 'NETWR'  'VBAP'.
    * Display the third list
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          it_fieldcat = lt_fieldcat
        TABLES
          t_outtab    = gt_vbap.
    ENDFORM.                               " F_DISPLAY_DATA_VBAP
    3rd Example
    ** Macro definition*
    *DEFINE m_fieldcat.*
      *add 1 to ls_fieldcat-col_pos.*
      *ls_fieldcat-fieldname   = &1.*
      *ls_fieldcat-ref_tabname = &2.*
      *append ls_fieldcat to lt_fieldcat.*
    *END-OF-DEFINITION.*
    *CONSTANTS :*
      *c_x VALUE 'X'.*
    *TYPE-POOLS: slis.                      " ALV Global types*
    *TYPES:*
    ** Data displayed in the first list*
      *BEGIN OF ty_vbak,*
        *vkorg TYPE vbak-vkorg,             " Sales organization*
        *kunnr TYPE vbak-kunnr,             " Sold-to party*
        *vbeln TYPE vbak-vbeln,             " Sales document*
        *netwr TYPE vbak-netwr,             " Net Value of the Sales Order*
      *END OF ty_vbak,*
    ** Data displayed in the popup list*
      *BEGIN OF ty_vbap,*
        *posnr  TYPE vbap-posnr,            " Sales document item*
        *matnr  TYPE vbap-matnr,            " Material number*
        *arktx  TYPE vbap-arktx,            " Short text for sales order item*
        *kwmeng TYPE vbap-kwmeng,           " Order quantity*
        *netwr  TYPE vbap-netwr,            " Net value of the order item*
      *END OF ty_vbap.*
    *DATA :*
      *g_vkorg TYPE vbak-vkorg,*
      *g_kunnr TYPE vbak-kunnr,*
      *g_vbeln TYPE vbak-vbeln,*
      *gt_vbak TYPE TABLE OF ty_vbak,*
      *gt_vbap TYPE TABLE OF ty_vbap.*
    *SELECT-OPTIONS :*
      *s_vkorg FOR g_vkorg,                 " Sales organization*
      *s_kunnr FOR g_kunnr,                 " Sold-to party*
      *s_vbeln FOR g_vbeln.                 " Sales document*
    *SELECTION-SCREEN :*
      *SKIP, BEGIN OF LINE,COMMENT 5(27) v_1 FOR FIELD p_max.    "#EC NEEDED*
    *PARAMETERS p_max(2) TYPE n DEFAULT '20' OBLIGATORY.*
    *SELECTION-SCREEN END OF LINE.*
    *INITIALIZATION.*
      *v_1 = 'Maximum of records to read'.*
    *START-OF-SELECTION.*
      *PERFORM f_read_data_vbak.*
      *PERFORM f_display_data_vbak.*
    **      Form  f_read_data_vbak*
    *FORM f_read_data_vbak.*
      *SELECT vkorg kunnr vbeln netwr*
        *INTO TABLE gt_vbak*
        *FROM vbak*
          *UP TO p_max ROWS*
       *WHERE kunnr IN s_kunnr*
         *AND vbeln IN s_vbeln*
         *AND vkorg IN s_vkorg.*
    *ENDFORM.                               " F_READ_DATA_VBAK*
    **      Form  f_display_data_vbak*
    *FORM f_display_data_vbak.*
      *DATA:*
        *ls_fieldcat TYPE slis_fieldcat_alv,*
        *lt_fieldcat TYPE slis_t_fieldcat_alv.*
    ** Build the field catalog*
      *m_fieldcat 'VKORG' 'VBAK'.*
      *m_fieldcat 'KUNNR' 'VBAK'.*
      *m_fieldcat 'VBELN' 'VBAK'.*
      *m_fieldcat 'NETWR' 'VBAK'.*
    ** Display the first list*
      *CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'*
        *EXPORTING*
          *i_callback_program      = sy-cprog*
          *i_callback_user_command = 'USER_COMMAND'*
          *it_fieldcat             = lt_fieldcat*
        *TABLES*
          *t_outtab                = gt_vbak.*
    *ENDFORM.                               " F_DISPLAY_DATA_VBAK*
    **       FORM USER_COMMAND                                             **
    *FORM user_command USING u_ucomm     TYPE sy-ucomm*
                            *us_selfield TYPE slis_selfield.     "#EC CALLED*
      *DATA:*
        *ls_vbak TYPE ty_vbak.*
      *CASE u_ucomm.*
        *WHEN '&IC1'.*
          *READ TABLE gt_vbak INDEX us_selfield-tabindex INTO ls_vbak.*
          *CHECK sy-subrc EQ 0.*
          *PERFORM f_read_data_vbap         " Read data from VBAP*
            *USING ls_vbak-vbeln.*
          *PERFORM f_display_data_vbap.*
      *ENDCASE.*
    *ENDFORM.                               " USER_COMMAND*
    **      Form  f_read_data_vbap*
    *FORM f_read_data_vbap USING u_vbeln TYPE vbeln_va.*
      *SELECT posnr matnr arktx kwmeng netwr*
        *INTO TABLE gt_vbap*
        *FROM vbap*
       *WHERE vbeln = u_vbeln.*
    *ENDFORM.                               " F_READ_DATA_VBAP*
    **      Form  f_display_data_vbap*
    *FORM f_display_data_vbap.*
      *DATA:*
        *ls_private  TYPE slis_data_caller_exit,*
        *ls_fieldcat TYPE slis_fieldcat_alv,*
        *lt_fieldcat TYPE slis_t_fieldcat_alv.*
    ** Build the field catalog*
      *m_fieldcat 'POSNR'  'VBAP'.*
      *m_fieldcat 'MATNR'  'VBAP'.*
      *m_fieldcat 'ARKTX'  'VBAP'.*
      *m_fieldcat 'KWMENG' 'VBAP'.*
      *m_fieldcat 'NETWR'  'VBAP'.*
      *ls_private-columnopt = c_x.          " Optimize width*
    ** Display items in a POPUP*
      *CALL FUNCTION 'REUSE_ALV_POPUP_TO_SELECT'*
        *EXPORTING*
          *i_selection = ' '*
          *i_tabname   = 'GT_VBAP'*
          *it_fieldcat = lt_fieldcat*
          *is_private  = ls_private*
        *TABLES*
          *t_outtab    = gt_vbap.*
    *ENDFORM.                               " F_DISPLAY_DATA_VBAP*
    ***************** END OF PROGRAM Z_ALV_GRID_AND_POPUP *******************
    reward if helpful
    raam

  • Can it be easier when running  simple examples in jmstutor

    Hi, I'm a new user of java. when I tried to use Simple examples in jms_tutorials, such as SimpleQueueSender.java, I found I had to type a long command:
    java -Djms.properites=%J2EE_HOME%\config\jms_client.properties SimpleQueueSender MyQueue 3
    It seems a little inconvienent.
    Can I first set the properties, then run the programe?
    How?
    Thanks a lot!

    You could put the command in a script and run it that way. But you do need to pass that -D option to the java command at J2EE 1.3.1.
    You could move to J2EE 1.4 Beta and use the J2EE Tutorial Addendum, which simplifies running the examples by providing Ant build scripts.
    Kim Haase
    Technical Writer
    Sun Microsystems, Inc.

  • Simple Example of PDK Servlet and PreferenceStore

    I'm currently using Portal 10g, Release 2. Unfortunately, there are no newly updated PDK samples available for this version, but I've referenced the previous Portal examples and haven't been able to find a simple example that walks through the entire process of establishing/registering a store, storing preference data, and reading preference data from a PDK Servlet.
    If anyone has examples that illustrate the following, it would be greatly appreciated:
    1. How to create a File-based PreferenceStore for an PDK HttpServlet
    2. How to associate a preference store with the Portlet (when using the PortletRequestRender.getProviderInstance().getPreferenceStore(), I get null)
    3. How to store a preference value in the store
    4. How to read a preference value in the store
    Note: I have been able (with far too much code given a "development kit") to use the PDK to create a File-base PreferenceStore and store values. Unfortunately the read operations look for the .dat file in a path that consists of the path that I established in the store and appends it with a value of /df/. As a result, the preferences can't be read.
    Thanks for any opinions/advice on this.
    John

    Hi John,
    You could try looking up at any sample portlets on the Portal Integration website: http://www.oracle.com/technology/products/ias/portal/point.html
    All the JPDK based portlets use file preference stores.
    1. How to create a File-based PreferenceStore for an
    PDK HttpServlet
    2. How to associate a preference store with the
    Portlet (when using the
    PortletRequestRender.getProviderInstance().getPreferen
    eStore(), I get null)You need to use the following code:
    // Get access to the PortletRenderRequest
    PortletRenderRequest pReq = (PortletRenderRequest)
    request.getAttribute(HttpCommonConstants.PORTLET_RENDER_REQUEST);
    // Get access to the user's preference store for this portlet
    NameValuePersonalizationObject data = (NameValuePersonalizationObject)
    PortletRendererUtil.getEditData(pReq);
    // Get access to the Edit Defaults data which would be applciable to all users (who have not yet customized that attribute)
    NameValuePersonalizationObject editData = (NameValuePersonalizationObject)
    PortletRendererUtil.getEditDefaultData(pReq);
    3. How to store a preference value in the store
    4. How to read a preference value in the storeLook at the APIs for NameValuePersonalizationObject at http://www.oracle.com/technology/products/ias/portal/html/javadoc/apidoc/index.html
    >
    Note: I have been able (with far too much code given
    a "development kit") to use the PDK to create a
    File-base PreferenceStore and store values.
    Unfortunately the read operations look for the .dat
    file in a path that consists of the path that I
    established in the store and appends it with a value
    of /df/. As a result, the preferences can't be
    read.
    Thanks for any opinions/advice on this.
    JohnI hope this helps ..
    thanks,
    Harsha

  • HELP: JSP simple examples

    Hi:
    i am a newbie to JSP and am trying to come up with few SIMPLE example JSP pages QUICKLY e.g.
    -using URL variables
    -form submission
    -email
    etc.
    could you give reference to simple code or tutorial which covers it.
    appreciate your help
    -Z

    Did you try downloading Tomcat and running through their examples? They're pretty elementary, show all the examples you mention (including an email example) and show the source code.
    Download/install Tomcat, get it running, and go to http://localhost:8080/examples/jsp/ for the JSP examples.

  • NIO with SSLEngine API - Simple example required

    Hi
    I am trying to implement a NIO Server with SSL Engine based implementation. I went through the Https server given in the samples provided with jdk 5.0. But that is little bit more complicated (uses Handlers and other associated functionality). what I am looking for is a simple example program which can elucidate the SSL Engine API operations and the bare minium code to execute a simple Client Server communication through SSL Engine. I know it has a long learning curve, just thought if somebody has researched well and posted an article/tutorial in this regard, it would be really helpful for novice programmers like me. Please help with some sample programs..
    Thanks

    Unfortunately the bare minimum is extremely complicated. The JSSE samples contain some simplistic NIO code but it barely works, and doesn't cope with useClientMode=true at the server, or with re-handshakes.
    There is some PD code out there if you can find it, and also several discussions in the Secure Sockets forum.
    There is also an entire chapter on it in my book http://www.telekinesis.com.au/wipv3_6/FundamentalNetworkingInJava.A21.

  • Does anyone tryed to apply mvc to a simple example ?

    does anyone tryed to implement mvc to a simple example ?
    Regards
    Tinnitus
    CLAD / Labview 2011, Win Xp
    Mission d'une semaine- à plusieurs mois laissez moi un MP...
    RP et Midi-pyrénées .Km+++ si possibilité de télétravail
    Kudos always accepted / Les petits clicks jaunes sont toujours appréciés
    Don't forget to valid a good answer / pensez à valider une réponse correcte

    You are right
    using simple I would like to say confined to the minimum
    i'm familiar with classes,  value references  and thread communcation
    each paradigm could be a step a first sight but the effort is rewarded afterward
    but it seems to be hard to find starting elements on mvc with labview
    I just come to discover mvc architecture, the theorie look nice but i'm not sure
    to understand enough to applicate , that why i'm looking for examples
    may be have you link to a good tutorial  ( not lined to a specific language) that could help me to start with labview
    Regards
    Tinnitus
    CLAD / Labview 2011, Win Xp
    Mission d'une semaine- à plusieurs mois laissez moi un MP...
    RP et Midi-pyrénées .Km+++ si possibilité de télétravail
    Kudos always accepted / Les petits clicks jaunes sont toujours appréciés
    Don't forget to valid a good answer / pensez à valider une réponse correcte

  • Simple example

    I am very proficient in java, but I am new to jdb. I have read all the "tutorial" and I have an understanding of how to use the tool to execute a java program, but I was wondering if someone might post a simple example of how I would use this technology in creating my own debugger.

    By "tutorial", I believe you mean the documents at:
    http://java.sun.com/products/jpda/
    In particular, the platform architecture document is useful
    because it shows where the different debug APIs operate:
    http://java.sun.com/j2se/1.4.1/docs/guide/jpda/architecture.html
    After reading the overview docs, I suggest you start by taking
    a look at the example source code, which is described here:
    http://java.sun.com/products/jpda/examples.html
    The example source code is included in your J2SE 1.4.xx bundle
    under the demo directory. Look in $JAVA_HOME/demo/jpda/examples.jar
    To compile or run the examples, you need to add
    $JAVA_HOME/lib/tools.jar to your classpath.
    After you unpack examples jar, look for
    com/sun/tools/example/trace/Trace.java
    After you understand the trace example, take a look
    at the source for jdb. That will be located under:
    com/sun/tools/example/debug/tty

  • Trouble with customer-cmp-ear example for new sun application server 9.0

    recently, i have been playing with sun Java system application server 9.0 and try a couple of examples, but i was in trouble. for example, i try customer-cmp-ear example, and i can create db, but i can not Set up JDBC resources, and i always get the following error:
    CLI146 /path/to/passwordfile does not exist in the file system or read permission denied.
    i take a look at the description of the example, one thing i do not quite understand, at the common instruction, i am required to set javaee.server.passwordfile property, does it mean i have to create a passwordfile? where do I put it ? i hope someone can help me, i will really appreciate it.
    Message was edited by:
    junjun

    I solved it.
    Change the file"build.properties.sample" to
    "build.properties"
    Maybe it's a bug in J2ee TutorialThe instructions in the About chapter tell you to copy build.properties.sample to build.propertieshttp://java.sun.com/javaee/5/docs/tutorial/doc/?wp405013&About.html#wp87965
    -Ian

  • Explaination and a simple example on TagExtraInfo class anyone ??

    Hi Guys,
    Could anyone please explain the concept of TagExtraInfo class and give a simple example with code. This one is really urgent !!
    Thanks
    Rasmeet

    Is this a genuine forum topic ? Or are we seeing the birth of some new encrytion algorithm here.
    Assuming its the former,...
    Have you seen http://java.sun.com/j2ee/tutorial/doc/JSPTags5.html#68067

Maybe you are looking for