How to set the caption text of a node with user object.

This is my problem for two days below is my sample code. I need to associate object with the tree node but the node is displaying the toString() value of the object. It should display the text I wanna see.
Please help. I was from the JSP world so Swing is quiet new to me, only this year I got again a project in swing.
TreeMap treemap = new TreeMap();
treemap.put("3","3");
treemap.put("5","4");
treemap.put("4","4");
treemap.put("1","1");
treemap.put("2","2");
DefaultMutableTreeNode nodetable = new DefaultMutableTreeNode(treemap,true);
DefaultTreeModel model = (DefaultTreeModel)jtree.getModel();
model.insertNodeInto(nodetable, nodetop,nodetop.getChildCount());

I have created a subclass of DefaultMutableTreeNode, I just have one question with my Default Constructor, is it correct? Suppose to be it should be super(Object userObject ,boolean allowChildren)?
But when I do that it does not compile.
Please correct me if I am wrong. I suspect my contructor inside code super() is not enough the parameters got lost. (btw) i will give you the dukes, please just verify my code.
Thanks.
class MyDefaultMutableTreeNode extends DefaultMutableTreeNode{
public String caption="";
public MyDefaultMutableTreeNode(Object userObject ,boolean allowChildren){
super();
public void setCaptionString(String str){
caption = str;
public String toString(){
return caption;
}

Similar Messages

  • How can I set the caption text of picture controls inside an array or how can I choose which array element is assigned using the array elements caption text property.

    I have 8 picture controls inside an array and I would like to set the caption text of these controls.
    I have used the property node of the array and used the array elements property caption text to set the text.
    The problem is however that I set the same text to all the picture controls inside the array.
    My question is how to set caption text of specific elements (Picture control) that I have so far only been able to access using the array elements caption text property.

    Some more help
    1 You could use the caption of the array and place it in front of the selected picture and update that using property nodes.
    2 Like Norbett said if you use a cluster of pictures then their caption can be updated individually.
    Here is a an example that demonstrates the above
    David
    Attachments:
    Modify the Captions Of Pictures.vi ‏83 KB

  • How to set the default text in an input box or a label to be a predefine, multiline text

    how to set the default text in an input box or a label to be a predefine, multiline text. In other words how to break the line in the code of a text box.
    thank you

    There are a couple of ways of doing this:
    If you're editing on the canvas, press Shift + Enter.
    If you're working in Express View (see lower right hand corner of Project Siena), you'll need to copy a hard return from another app such as Notepad.
    I believe a better implementation of hard returns are in the list of requested functionality that you can find here:
    https://social.technet.microsoft.com/Forums/en-US/2e1f9446-56b2-419a-9c17-7037d2cd6146/from-the-community-overview-of-requested-additional-functionality?forum=projectsiena
    Thor

  • How to set Tool Tip Text to Tree Node?

    Hi,
    How to set Tool Tip Text to Tree Node in JTree?
    Pls somebody help me to solve it.

    bsampeieri,
    Been here a long time myself. I don't agree with the one post is enough per se. That is to say, sometimes, it helps to post in several groups so that more eyes may see it. A number of forum posters linger in specific forum topics and may not see the post in another forum.
    Now, if in the previous post you/others answered the question and then the OP posted here later, I could see the complaint.
    For the OP, the better way to cross-post is to have one "main" post, then have all the other posts refer back to that one (link to it) so that people aren't duplicating the effort to answer your question(s). A simple "I have cross-posted this to get more eyes on it. Please reply to this question at this post <link here>"

  • How to set the "Purpose" text on an Activity?

    Hi,
    I want to create Activities via API. In the UI I see there the fields Name and Purpose. I know how to set the name. But how do I set the purpose via API?
    Thanks, Dieter

    Hi,
    ok, I figured it out: you need a <purpose>.....</purpose> tag in the create XML. I put it as a child node to the <activity> tag. Works fine. Well, it is not described in the API description. There it talks only about the <activity> tag, or i completely overlook the obvious.So, next question: is there a complete scheme description available? Would be quite helpful.
    Regards, Dieter

  • How to set the horisontal offset for a node relative its parent in JTree?

    When using large icons for nodes in a JTree the whole tree looks very compact. I found a method setRowHeight(int height) to set the row height that got med some space between the rows. But I couldn't find a simular method to increase the offset between a child node and its parent.
    Any suggestions?

    You can control the offset through the BasicTreeUI, as discussed in this thread:
    http://forum.java.sun.com/thread.jspa?threadID=630707&messageID=3636590
    See reply #8 and #9.

  • How to set the snc name to abap server with IDM?

    HI all:
         I want to set the snc name from IDM , but I didn't konw  which attribute that I would be set.
    I there anyone konw this?
    thanks!

    Hi Shi,
    I'm guessing you don't know which attribute in the MX_PERSON class contains it?
    If this is what you meant, then there isn't a default attribute for that, you can either create one manually or let the synch process create it by enabling "automatic attribute creation" setting for the Identity Store.
    Eric

  • How to set the control-on hierarchical tree nodes

    Hi,
    I have created form in which at the left it has hierarchical tree structure(BOM) and towards the right it brings up the query results for selected node.
    Now, I have a button upon clicking which I navigate to the root node by issuing
    "Ftree.set_Tree_selection(htree, 1, Ftree.select_on);".
    But, it cannot automatically run the ' when-tree-node-selected' trigger '.
    any solution???
    Its really urgent.I have a customer demo on monday.
    Please help me asap.
    regards,
    Nagadeep.

    Hello Nagadeep,
    couldn't you just put the code from the trigger into a procedure
    and run that after the navigation to the item?
    Just a thought,
    Bernd
    The docs state that:
    No programmatic action will cause the When-Tree-Node-Selected trigger to fire. Only end-user action will generate an event.
    Probably due to performance reasons.
    Bernd
    Message was edited by:
    Bernd Prechtl

  • IBooks Author: How do you get the inset margins applied to the caption text of gallery widgets to preview correctly on an iPad?

    Currently the inset margins I set for caption text in the gallery widget resets to zero when previewed on different iPads. These are galleries with different images and the captions are set to “individual caption per image” in the interaction panel.
    BUT the inset margins will preview correctly if the gallery caption is set to “same caption for all images” in the widget interactions panel. How does one go about fixing this in iBooks Author? Would love to hear others advice or suggestions or work arounds. Thanks!

    I found this article that shows the folder we are looking for is here --
    ~/Library/Containers/com.apple.iBooksX/Data/Documents/AEAnnotation/
    per http://mjtsai.com/blog/2013/11/06/the-problem-with-ibooks/ and http://computers.tutsplus.com/tutorials/beyond-highlighting-how-to-get-the-most- from-your-annotations--cms-20013
    So I opened the files in TextWrangler to search for a word I know I highlighted in a particular book.  That helped me identify the correct file for the book I am concerned with.  I did a Time Machine restore of the file and got my notes back the way they were.

  • IBooks Author: How do you get the inset margins applied to the caption text of gallery widgets to preview correctly?

    Currently the inset margins I set for caption text in the gallery widget reset to zero when previewed on different iPads. These galleries have multiple images and the captions are set to "individual caption per image" on the widget interaction panel. BUT the inset margins preview correctly if the gallery caption is set to "same caption for all images" in the gallery widget interaction panel. How does one fix this in iBooks Author? Would appreciate any advice or work arounds or suggestions.
    Thanks!

    The arrows don't show up on the iPad, they are only to aid navigation within iBA. You can use boxes in the background to frame your galleries (as the background is off). I believe it's also possible to change the colour of the dots beneath the gallery too, although I forget how to do that right now.
    About Apple's rigid UX – I agree that it can be frustrating. Apple intended iBA to be used by everyone, and the sort of design options and customisability we might want may confuse the less experienced user. Apple also wanted the UI for every book to be the same – from the point of view of the new user, once you've used one iBA ebook (or iBook, I'm not sure what Apple want us to call it), you can use them all. Otherwise end users would to get used to a slightly different UI on each book, which kind of works against the idea that ideally UI should be intuitive enough to be invisible. I can see the point in that. I have created a 'How to use' section in every iBA file I've made. It get's old quickly.
    Oh, and (you probably know this, but…) you can choose your own custom icon for audio. It's limited, as it's only a placeholder image that allows you to play an audio file, there's no ability to pause the audio or stop it once you choose the view as thumbnail choice. Something I'd like to see changed.
    Here's a link to Apple feedback page for iBA. Feel free to hammer it with your suggestions.
    https://www.apple.com/feedback/ibooks-author.html

  • How do I set the default text in a bound textbox?

    How do I set the default value of a bound textbox when the AddNewItem button on the MenuStrip is clicked?
     I have the following code (see below), but for some reason it does work when I put the code in the
    AddNewItem_Click event; however, it does work if I put it in the
    Form's Load Event. The statement in question is Me.txtBusUsagePct.Text = 100.
    What am I doing wrong? Why can't I set the default text in the AddNewItem_Click
    event?
       Private Sub BindingNavigatorAddNewItem_Click(sender As Object, e As EventArgs) Handles BindingNavigatorAddNewItem.Click
    Me.txtBusUsagePct.Text = "100"
       End Sub
    BobV365

    Hello,
    Here I am using mocked up data but the important thing is after loading the data. Requires on the form a BindingNavigator and two text boxes.
    Public Class Form1
    WithEvents bsData As New BindingSource
    Private Sub Form1_Load(
    ByVal sender As System.Object,
    ByVal e As System.EventArgs) Handles MyBase.Load
    Using MockedData As New DataTable()
    MockedData.Columns.AddRange(New DataColumn() _
    New DataColumn("PartName", GetType(String)),
    New DataColumn("partqty", GetType(Int32))
    MockedData.Rows.Add(New Object() {"Part A", 100})
    MockedData.Rows.Add(New Object() {"Part 99", 34})
    MockedData.Rows.Add(New Object() {"Part B", 4})
    bsData.DataSource = MockedData
    End Using
    CType(bsData.DataSource, DataTable).AcceptChanges()
    BindingNavigator1.BindingSource = bsData
    TextBox1.DataBindings.Add("Text", bsData, "Partname")
    TextBox2.DataBindings.Add("Text", bsData, "partqty")
    End Sub
    Private Sub bsData_AddingNew(
    ByVal sender As Object,
    ByVal e As System.ComponentModel.AddingNewEventArgs) _
    Handles bsData.AddingNew
    Dim dv As DataView = TryCast(bsData.List, DataView)
    Dim rv As DataRowView = dv.AddNew()
    rv("PartName") = "(new)"
    rv("partqty") = 0
    e.NewObject = rv
    bsData.MoveLast()
    End Sub
    End Class
    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my webpage under my profile
    but do not reply to forum questions.

  • How to set a Caption/title in ALv

    Hi frnds,
    Can you tell me how to set a caption/title to a ALV grid.
    Regards
    Anuj

    hi
    try like this
    DATA: i_title_kna1 TYPE lvc_title VALUE 'FIRST LIST DISPLAYED',
          i_title_vbak TYPE lvc_title VALUE 'SECOND LIST DISPLAYED'.
    populate additional paramete as follows.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
         i_callback_program                = sy-repid
       i_callback_pf_status_set          = 'PF_STATUS_SET'
         i_callback_user_command           = 'USER_COMMAND'
       i_callback_top_of_page            = 'TOP-OF-PAGE'
         i_grid_title                      = i_title_kna1
         is_layout                         = wa_layout
         it_fieldcat                       = it_fieldcat
       it_events                         = it_events
        TABLES
          t_outtab                          = it_kna1.
    or if you want top of page
    populate the events table and use alv_commentary_write
      wa_listheader-typ = 'H'.
      wa_listheader-info = 'Customer Details'.
      APPEND wa_listheader TO it_listheader.
      CLEAR wa_listheader.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary       = it_listheader
          i_logo                   = 'EDSLOGO'
      I_END_OF_LIST_GRID       =
      I_ALV_FORM               =
      REFRESH it_listheader.
    try the below code u will get a clear picture
    report zalv no standard page heading.
    TYPE-POOLS : slis.
    TABLES: kna1.
    TYPES : BEGIN OF ty_kna1 ,
            kunnr LIKE kna1-kunnr,
            name1 LIKE kna1-name1,
            land1 LIKE kna1-land1,
            END OF ty_kna1.
    DATA: it_kna1 TYPE TABLE OF ty_kna1.
    DATA : it_fieldcat TYPE slis_t_fieldcat_alv,
           wa_fieldcat TYPE slis_fieldcat_alv.
    DATA : wa_layout TYPE slis_layout_alv .
    DATA : it_events TYPE  slis_t_event ,
           wa_events TYPE slis_alv_event.
    DATA : it_listheader TYPE slis_t_listheader,
           wa_listheader TYPE slis_listheader,
           it1_listheader TYPE slis_t_listheader,
           wa1_listheader TYPE slis_listheader.
    DATA: i_title_kna1 TYPE lvc_title VALUE 'FIRST LIST DISPLAYED'.
    INITIALIZATION.
      PERFORM getevents using it_events.
      PERFORM desinlayout.
    START-OF-SELECTION.
      PERFORM desinfieldcat.
      PERFORM datafetching.
      PERFORM display.
    *&      Form  desinfieldcat
          text
    -->  p1        text
    <--  p2        text
    FORM desinfieldcat .
    wa_fieldcat-row_pos = 1.
      wa_fieldcat-col_pos = 1.
      wa_fieldcat-fieldname = 'KUNNR'.
      wa_fieldcat-seltext_l = 'Cust Num'.
      wa_fieldcat-datatype = 'CHAR'.
      wa_fieldcat-outputlen = 10.
      wa_fieldcat-tabname = 'IT_KNA1'.
      wa_fieldcat-key = 'X'.
    wa_fieldcat-hotspot = 'X'.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR wa_fieldcat.
    wa_fieldcat-row_pos = 2.
      wa_fieldcat-col_pos = 2.
      wa_fieldcat-fieldname = 'NAME1'.
      wa_fieldcat-seltext_l = 'Name'.
      wa_fieldcat-datatype = 'CHAR'.
      wa_fieldcat-outputlen = 35.
      wa_fieldcat-tabname = 'IT_KNA1'.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR wa_fieldcat.
    wa_fieldcat-row_pos = 3.
      wa_fieldcat-col_pos = 3.
      wa_fieldcat-fieldname = 'LAND1'.
      wa_fieldcat-seltext_l = 'Country'.
      wa_fieldcat-datatype = 'CHAR'.
      wa_fieldcat-outputlen = 10.
      wa_fieldcat-tabname = 'IT_KNA1'.
      APPEND wa_fieldcat TO it_fieldcat.
      CLEAR wa_fieldcat.
    ENDFORM.                    " desinfieldcat
    *&      Form  datafetching
          text
    -->  p1        text
    <--  p2        text
    FORM datafetching .
      SELECT kunnr name1 land1
             FROM kna1
             INTO TABLE it_kna1
             UP TO 30 ROWS.
    ENDFORM.                    " datafetching
    *&      Form  display
          text
    -->  p1        text
    <--  p2        text
    FORM display .
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
      EXPORTING
         i_callback_program                = sy-repid
       I_GRID_TITLE                      = i_title_kna1
         is_layout                         = wa_layout
         it_fieldcat                       = it_fieldcat
       it_events                         = it_events
        TABLES
          t_outtab                          = it_kna1.
    ENDFORM.                    " display
    *&      Form  desinlayout
          text
    -->  p1        text
    <--  p2        text
    FORM desinlayout .
      wa_layout-zebra = 'X'.
      wa_layout-colwidth_optimize = 'X'.
    *wa_layout-edit = 'X'.
    ENDFORM.                    " desinlayout
    *&      Form  getevents
          text
    -->  p1        text
    <--  p2        text
    FORM getevents using p_it_events type slis_t_event.
      CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
       EXPORTING
         I_LIST_TYPE           = 0
      IMPORTING
         et_events             = p_it_events
       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.
    READ TABLE p_it_events INTO wa_events WITH KEY name = 'TOP_OF_PAGE'.
      wa_events-form = 'TOP_OF_PAGE'.
      MODIFY it_events FROM wa_events TRANSPORTING form WHERE name = wa_events-name.
    ENDFORM.                    " getevents
    *&      Form  populatevents
          text
    -->  p1        text
    <--  p2        text
    FORM populatevents .
      READ TABLE it_events INTO wa_events WITH KEY name = 'TOP_OF_PAGE'.
      wa_events-form = 'TOP_OF_PAGE'.
      MODIFY it_events FROM wa_events TRANSPORTING form WHERE name = wa_events-name.
    ENDFORM.                    " populatevents
    *&      Form  top-of-page
          text
    FORM TOP_OF_PAGE.
      wa_listheader-typ = 'H'.
      wa_listheader-info = 'Customer Details'.
      APPEND wa_listheader TO it_listheader.
      CLEAR wa_listheader.
      CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
        EXPORTING
          it_list_commentary       = it_listheader
          i_logo                   = 'EDSLOGO'
      REFRESH it_listheader.
    ENDFORM.                    "top-of-page
    REWARD IF HELPFUL
    PRASANTH

  • How to set the parameter

    hi i am creating xml publisher and from OAF with parameters
    cusname:
    runreportdate:
    go clear buttons
    click go open report in pdf
    SELECT hp.party_name CustomerName,
      csi.incident_number SRNumber,
      to_char(csi.incident_date,'DD-MON-YYYY') SRDate,
      to_char(csi.close_date,'DD-MON-YYYY') SRCloseDate,
      mtl.description SRItemName,
      csi.summary Summary,
      csi.problem_code,
      csi.incident_address SRAddress,
      csi.INCIDENT_COUNTRY SRCountry,
      '31-DEC-2008' Reportrundate,
      COUNT ( * ) over () cnt,
      cis.name,
      COUNT(
      CASE
        WHEN cis.name='Low'
        THEN 1
      END) over () Low,
      COUNT(
      CASE
        WHEN cis.name='Medium'
        THEN 1
      END) over () Medium,
      COUNT(
      CASE
        WHEN cis.name='High'
        THEN 1
      END) over () High1,
    to_char(csi.incident_date,'MON-YYYY') SrMonth
    FROM hz_parties hp,
      hz_cust_accounts hca,
      hz_contact_points hc,
      cs_incidents_all_b csi,
      ar_lookups arl,
      cs_incident_severities_b cis,
      mtl_system_items_kfv mtl
    WHERE hca.cust_account_id   =csi.account_id
    AND hp.party_type          IN ('PERSON','ORGANIZATION')
    AND hp.status               ='A'
    AND hp.party_id             = hca.party_id
    AND hca.status              ='A'
    AND hp.party_id             =hc.owner_table_id(+)
    AND hc.owner_table_name(+)  ='HZ_PARTIES'
    AND hp.party_id             =hca.cust_account_id
    AND hc.contact_point_type(+)='PHONE'
    AND hc.primary_flag(+)      ='Y'
    AND hc.status(+)            ='A'
    AND arl.lookup_type(+)      = 'PHONE_LINE_TYPE'
    AND arl.lookup_code(+)      = hc.phone_line_type
    AND hp.party_name='Business World'
    AND csi.incident_date BETWEEN to_date('01-JAN-2000','DD-MON-YYYY') AND to_date('31-DEC-2008','DD-MON-YYYY')
    AND cis.incident_severity_id=csi.incident_severity_id
    AND mtl.inventory_item_id=csi.inventory_item_id
    GROUP BY hp.party_name,
      csi.incident_number,
      csi.incident_date,
      csi.close_date,
      csi.summary,
      csi.problem_code,
      csi.incident_address,
      cis.name,
      csi.INCIDENT_COUNTRY,
      mtl.description,
      to_char(csi.incident_date,'MON-YYYY')
    Am code
        public void initQuery(String paramString1, String paramString2)
              SrReportVOImpl vo=getSrReportVO1();
            if ((paramString1 != null) && (!("".equals(paramString1.trim()))) && (paramString2 != null) && (!("".equals(paramString2.trim()))))
              vo.setWhereClauseParams(null);
              vo.setWhereClauseParam(0, paramString1);
              vo.setWhereClauseParam(1, paramString2);
              vo.executeQuery();
        public XMLNode getPrintDataXML()
        //SrReportVOImpl vo=getSrReportVO1();
        OAViewObject vo = (OAViewObject)findViewObject("SrReportVO1");
        //vo.initQuery(s,s1);
        XMLNode xmlNode=(XMLNode) vo.writeXML(4,XMLInterface.XML_OPT_ALL_ROWS);
            return xmlNode;
    CO code
          SrAMImpl am=(SrAMImpl)pageContext.getApplicationModule(webBean);
          if(pageContext.getParameter("Go")!=null)
              //am.searchSrDetails(pageContext,webBean);   
               String s=pageContext.getParameter("CustomerName");
               String s1=pageContext.getParameter("RunReportDate");
                   am.initQuery(s,s1);
                 // Get the HttpServletResponse object from the PageContext. The report output is written to HttpServletResponse.
                 DataObject sessionDictionary = (DataObject)pageContext.getNamedDataObject("_SessionParameters");
                 HttpServletResponse response = (HttpServletResponse)sessionDictionary.selectValue(null,"HttpServletResponse");
                 try {
                 ServletOutputStream os = response.getOutputStream();
                 // Set the Output Report File Name and Content Type
                 String contentDisposition ="attachment;filename=ServiceReport.pdf";
                 response.setHeader("Content-Disposition",contentDisposition);
                 response.setContentType("application/pdf");
                     Serializable param[]={pageContext.getParameter("CustomerName"),pageContext.getParameter("RunReportDate")};
                     System.out.println("hiiii 12");
                     // Get the Data XML Output as the XMLNode
                     XMLNode xmlNode = (XMLNode) am.invokeMethod("getPrintDataXML",param);
                     System.out.println("hiiii 13");
                     System.out.println(xmlNode.toString());
                     System.out.println("hiiii 14");
                 // Get the Data XML File as the XMLNode
                 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
                 xmlNode.print(outputStream);
                 ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
                 ByteArrayOutputStream pdfFile = new ByteArrayOutputStream();
                 //Generate the PDF Report.
                 TemplateHelper.processTemplate(
                 ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getAppsContext(),
                 APP_NAME,
                 TEMPLATE_CODE,
                 ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getLanguage(),
                 ((OADBTransactionImpl)pageContext.getApplicationModule(webBean).getOADBTransaction()).getUserLocale().getCountry(),
                 inputStream,
                 TemplateHelper.OUTPUT_TYPE_PDF,
                 null,
                 pdfFile);
                 // Write the PDF Report to the HttpServletResponse object and flush.
                 byte[] b = pdfFile.toByteArray();
                 response.setContentLength(b.length);
                 os.write(b, 0, b.length);
                 os.flush();
                 os.close();
                 pdfFile.flush();
                 pdfFile.close();
                 catch(Exception e)
                 response.setContentType("text/html");
                 throw new OAException(e.getMessage(), OAException.ERROR);
                 pageContext.setDocumentRendered(false);
                   System.out.println("hiiii 13");
          if(pageContext.getParameter("Clear")!=null)
              am.ClearFields(pageContext,webBean);
          }can any one tell me how to set the bind parameters or setting parameter

    Hi,
    Could not understand your problem exactly. DId you try adding bind variables in the query like below:
    AND hp.party_name='Business World'
    AND csi.incident_date BETWEEN to_date('01-JAN-2000','DD-MON-YYYY') AND to_date('31-DEC-2008','DD-MON-YYYY')
    change to
    AND hp.party_name=:1
    AND csi.incident_date BETWEEN :2 AND :3
    Please note you will need three bind variables. Second and third for SR Dates.
    ~Amol

  • How to set the width of DataGridColumn dynamically?

    What I want to do is, load data from a text file and put into a DataGrid component, the fields of ech record in the text have fixed length, and are seperated by a space, like this:
    personal.txt
    50 Uvwxyz  Male    123456789
    60 Hijklmn  Male    67890123456789
    30 Abcdefg Male    123456789012345
    40 Opqrst   Female 987654321012345678
    the configuration file is column.xml:
    <dgcolumn>
         <personal>
              <len>20</len>
              <title>Name</title>
         </personal>
         <personal>
              <len>3</len>
              <title>Age</title>
         </personal>
         <personal>
              <len>6</len>
              <title>Sex</title>
         </personal>
         <personal>
              <len>20</len>
              <title>IdNumber</title>
         </personal>
    </dgcolumn>
    First I load the column.xml into an arrColumn, then read the personal.txt and seperate the record by the width( "len" in the xml file ), and put the seperated fields into another arrField, set the arrayFld as the dataProvider of a DataGrid, thus, the title can be showed as the headerText of the DataGrid and the data can be loaded correctly.
    private function handleComplete( event:Event ):void
         var arrField:Array = new Array();
         var arrFile:Array = loader.data.split(/\n/);
         for( var i:int = 0; i < arrColumn.length; i ++ )
              arrField[i] = convIcom( arrFile[i] );
         adgFile.dataProvider = arrField;
         trace( "The data has successfully loaded" );
    private function convIcom( strRecord:String ):Object
         var key:String = null;
         var dataField:String = null;
         var offset:int = 0;
         var obj:Object = new Object();
         if( strRecord.length > 0 )
              for( var i:int = 0; i < arrColumn.length; i ++ )
                   dataField = strRecord.substr( offset, arrColumn[i].len );
                   key = arrColumn[i].title;
                   obj[key] = dataField;
                   offset += arrColumn[i].len + 1;
         return obj;
    <mx:DataGrid x="10" y="100" width="400" id="dgFile" />
    The problem is, the width of the DataGridColumn is average, how to set the column width by the length of each field? I can calculate the rate of each field ( field / fields ), but I don't know how to change the property of the DataGridColumn.width.
    Thanks for helping.

    In the above post, I pasted an old version of personal.txt, so I paste it again:
    personal.txt
    Uvwxyz  50 Male   123456789
    Hijklmn 60 Male   67890123456789
    Opqrst  40 Female 987654321012345678
    Abcdefg 30 Male   123456789012345
    And I have another question, when the data is loaded into the DataGrid, the fields of each record are ordered in alphabetical order ( the "Age" column will appear firstly, then "IdNumber", "Name", "Sex" ), not as the order in column.xml, how to make it keep the sequence of the xml file?
    Thanks again.

  • How to set the value of something in a component from the main application?

    Hi,
    Maybe I've been working on this too long, but I can't figure
    out how to set the value of the text property of a text input field
    in a component from my main application in an mx:Script block. I
    have a component called Login in the components folder, and I need
    to set the text value of empNum. In my mxml declaration at that the
    top, I've declared these components as xmlns:c="components.*" So
    logically, the property I'm trying to set is c.Login.empNum.text. I
    can't figure out the correct syntax to get this to work, and I've
    tried everything I can think of. Does anyone have any suggestions?
    I'm thinking this should be an easy one, and I'm just missing
    something.
    Thanks!
    Holli

    Did you try giving it an id ?
    <c:MyLogin id="loginScreen" /c>
    So later you can do loginScreen .empNum.text = "my text"
    Laurent,

Maybe you are looking for