Dynamic buttons and itemlisteners????

I'm trying to do something that might not be possible. I would like to create some buttons and actions for those buttons on the fly. For example:
1) read some files from a directory (these file store settings)
2) Create buttons using the filenames as the button labels
3) Create associated actionPerformed section related to those buttons
I want to do this because the amount of files and there names could change all the time. Basically I want to create a button for each file, and essentially launch an application using the settings file as part of a process.
So far I've read a filename into a string. The first problem, how do I use that filename as the name of a button?
JButton "string value" = new JButton();
Then, subsequently, how to you set up the action? See code snipet below.
Hope that made some sense. Can anything like this be done?
Thanks,
James
//this loads the buttons
for (int i=0; i < main.size(); i++)
     Vector temp = new Vector();
     temp = (Vector)main.elementAt(i);
     JButton buttonName = new JButton((String)temp.elementAt(0));
     buttonName.addActionListener(this);
     northFlow.add(buttonName);
//this is in the actionPerformed section
for (int i=0; i < main.size(); i++)
     Vector temp = new Vector();
     temp = (Vector)main.elementAt(i);
     if (source == (String)temp.elementAt(0))
            loadProgram((String)temp.elementAt(0));

There is a way to give a button a variable name equal to the file name but it involves extremely advanced Java programming involving creating dynamic class instances. I would strongly discourage this approach because debugging it when it doesn't work, can be a nightmare.
There is a much easier way to do this however. Create an array of JButtons. Call it, oh say, "MyButtons". Then at the appropriate places, you can do:
JButton[] MyButtons;
MyButtons = new JButton[ main.size ];
for ( int i = 0; i < main.size(); i++ ) {
   Vector temp = new Vector();
   temp = (Vector)main.elementAt(i);
   MyButtons[i] = new JButton( (String)temp.elementAt(0) );
   MyButtons.addAction...
Incidently, you may also want to re-think your data structure. From what I understand, you have an array where each element is a vector (another array of zero or more elements). This results in code that is difficult to read and write. Consider making your own objects instead of using vectors, then you could write something like...
for ( int i = 0; i < main.size(); i++ ) {
   if ( source == main.getProgramName() ) {
loadProgram( main[i].getProgramName() );
The nice thing about this approach is that you can mix and match objects within the array, or add elements to each object in any particular order and it won't break the rest of your code.
P.S., use the square brackets to indicate arrays. For some reason, this board is converting them into angle brackets.

Similar Messages

  • Buttons and text items on oracle forms 6i

    can i create dynamic buttons and text fields on oracle forms 6i.
    i mean when i insert record in database then automatically creat a button on form.
    Regards
    Munawer hussain

    Hi,
    One physical button is enough for a series of "functional buttons" per amount of simultanious visisble buttons. You can change the button prompt at run-time depending on a certain condition. That same condition can also be used when executing the when-button-pressed (wbp) trigger.
    Example:
    suppose you have 2 functions that you want to create buttons for: enter query and execute query. Only 1 button is visible at one time. In design time you create 1 button. In run-time, depending on :system.mode you set the button prompt to "enter query"or "execute query" and in the wbp trigger you write
    begin
    if :system.mode = 'QUERY'
    then
    execute_query;
    else
    enter_query;
    end if;
    end;
    Kind regards
    .

  • Creation of satic and dynamic buttons in a view

    Hi,
    I have created a dynamic button using the code..
    DATA: lr_container TYPE REF TO cl_wd_uielement_container,
            lr_button TYPE REF TO cl_wd_button.
      CHECK first_time = abap_true.
      lr_container ?= view->get_element( id = 'ROOTUIELEMENTCONTAINER' ).
      cl_wd_matrix_layout=>new_matrix_layout( container = lr_container ).
      lr_button = cl_wd_button=>new_button( id         = 'BUTTON'
                                            text       = 'My Button'
                                            on_action  = 'ACTION' ).
      cl_wd_matrix_head_data=>new_matrix_head_data( element = lr_button ).
      lr_container->add_child( the_child = lr_button ).
    its working fine and iam able to see the button .....but when i create another button thorugh layout design its going for dump....whats the reason .?
    Cant we create static and dynamic buttons at a time?
    Thanks,.
    Shailaja Ainala.

    Hi Shailaja,
    Yes you can add static and dynamic ui elements together in the same view.
    The possible problem here could be the way in which the ui elements are added.
    You have created the dynamic button under the root container uielement.
    What about you static button ? Check your layout and layout data property.
    Thank You,
    Radhika.

  • Add dynamic buttons to each report row and bind the row data to buttons specific to that row

    I have a page with a form at the top and a report at the bottom which is tied to a table. I need to add a pair of buttons for each row of the table and add dynamic actions for these buttons. I need to submit the data corresponding to the row to a REST service and refresh the table/row. I know it is possible to add ajax call and refresh the table after the response is received. But I am not sure how I can dynamically include a pair of buttons on each row and have the access the data corresponding to the record when a particular button is clicked. I was not able to find such a feature using the help page. Can you please let me know if this is possible. Thanks in advance.
    Below is the representation of how I need the page to look like.
    Col 1
    Col 2
    Col 3
    data 1
    data 21
    data 31
    Button 1
    Button 2
    data 2
    data 22
    data 32
    Button 1
    Button 2
    data 3
    data 23
    data 33
    Button 1
    Button 2
    data 4
    data 24
    data 34
    Button 1
    Button 2
    I should be able to access data 1, data21, data 31 from button 11 and button21 etc.

    select data1,
              data2,
              data3,
              null button1,
              null button2,
              rowid r_id
    from .....
    If you edit the column for button1 and navigate to the Column Formatting region you can create your button here, several different ways.  You will need to play around with how you prefer.  See below:
    <input class="button1" type="button" id="#R_ID#" value="label for the button" /> or <button id="#R_ID#">label for button</button> or you could use <a> and apply css of your theme.
    You also create both buttons in a single column.  From here you can reference any of the columns from your select by using the #COLUNMNAME# format (as I did with R_ID).
    You will next need to something similar for all columns you want to be able to grab when you click the buttons.  See below:
    --- This would be for data1 column
    <span id="D1-#R_ID#">#DATA1#</span>
    You would do these for each column that you want access to when button clicked as mentioned above.  You could bypass this step and use jquery to traverse the DOM using .closest() and .find() and give each column a distinct class.  Is is your preference.
    You would then create a dynamic action triggered when .button1 is clicked.  Now that you have that object you can get the id of the triggering object which would be your r_id and from there you can access all your individual data points(all this done in a javascript in the dynamic action) and assign to hidden items on your page.  The next step of that dynamic action you could execute pl/sql and pass those in page items.
    Hope that all makes sense.
    David
    Message was edited by: DLittle
    Just as a bit of clarification:  the r_id column does not have to be rowid, but it does need to be unique for each row return.  You could use your primary key or rownum.  Whatever works for your scenario.

  • Button values in dynamic columns and rows

    Hi,
    I am working on webpage that allows the user to dynamically browse a database. I already did this as an applet and was asked to convert it to server-side intensive. Thus began my adventure into JSP and servlets.
    The problem i am having is that at some point a table is generated with a number of columns having submit buttons instead of just text. I want to get the column number and the value of the button that user clicks and use it in my servlet.
    Can anyone suggest a way to do this ?
    My current train of thoughts is to attach the column index to the name of the button and use javascript's onclick to call a function to set a hidden parameter. I am a novice to javascript - will it be possible to pass the name attribute of the button to the function ?
    Also, can I use jsp tags inside the javascript function ?
    TIA
    -Harry
    Below is the code for generating the page.
    <jsp:useBean id="tableData" scope="session" class="beans.TableBean" />
    <table border="1">
    <% int columnCount = tableData.getColumnCount(); %>
    <% int rowCount = tableData.getRowCount(); %>
    <tr align="center">
    <%for(int i=0; i < columnCount; i++)
    {%>
    <td>
    <%= tableData.getColumnTitle(i) %>
    </td>
    <%}%>
    </tr>
    <% for(int i=0; i<rowCount;i++)
    {%>
    <tr>
    <%for(int j=0; j<columnCount; j++)
    String val = tableData.getValueAt(i,j);
    %>
    <td>
    <%if(tableData.isDrill(j))
    %>
    <input type="submit" name="<%=val%>" value="<%=val%>" >
    <%}
    else
    {%>
    <%=val %>
    </td>
    <%}
    }%>
    </tr>
    <%}%>
    </table>

    Is there other data being passed to the servlet also... by the looks of the code you're using now, there isn't. If this is the case, why bother with submit buttons? You can just use an HTML button, and link it to the servlet passing the information you need, sending your column numbers as parameters inside the url,
    <input type="button" value="<%=val%>" onClick="window.location.href='myServlet?col=<%=j%>&val=<%=val%>';"

  • Generating buttons and listboxes dynamically on the screen

    Hi people!!
    There's a way to generate buttons and listboxes dynamically on the screen????
    Tks in advance
    Gabriel

    hi check this..
    Dynamic drop down list box

  • Dynamic radio button and group

    Hi, we have create dynamic radio button and group on “application creation complete” event , but which I am try to get number of radio button its show zero, see below code
    import flash.utils.setTimeout;
    import mx.controls.Alert;
    import mx.events.FlexEvent;
    import spark.components.RadioButton;
    import spark.components.RadioButtonGroup;
    private var  rbg:RadioButtonGroup;
    private var  rb1:RadioButton;
    private var  rb2:RadioButton;
    private var dcount:int = 0;
    protected function application1_creationCompleteHandler(event:FlexEvent):void
         // TODO Auto-generated method stub
         // TODO Auto-generated method stub
         rb1 = new RadioButton();
         rb2 = new RadioButton();
         rbg = new RadioButtonGroup();
         rb1.label = "Radio1";
         rb2.label = "Radio2";
         rb1.group = rbg;
         rb2.group = rbg;
         vbox1.addChild(rb1);
         vbox1.addChild(rb2);
         checkRadioButton (); 
    protected function checkRadioButton ():void
         Alert.show("In checkRadioButton function : " +  rb1.group.numRadioButtons.toString());
    If I put some Time interval to call  checkRadioButton function its working fine,
    //checkRadioButton (); 
    setTimeout(checkRadioButton,1000);
    but this is not best practice.
    why this happen ….can anybody  clear  this or any other way to do this.
    Thanks in advance

    @manjeet.patel,
    Just write the below line of code
    vbox1.validateNow();
    You need not use setTimeout() function
    vbox1.addChild(rb1);
    vbox1.addChild(rb2);
    vbox1.validateNow();
    Thanks,
    Bhasker

  • Creating dynamic Radio Buttons and Buttons

    Hello All,
    Presetly I am working on below functionality:
    I have an ArrayCollection which is like
    var sampleCollection:ArrayCollection = new ArrayCollection( [ {"filterID:1", filterName:"Occupied" },  {"filterID:2", filterName:"Unccupied" }] );
    Now my requirement is to create a RadioButton  and a Normal Button for every element in the ArrayCollection.
    So basically the UI will be "RadioButton, Occupied, Button, Button".
    Can someone help me in this respect.
    Thanks in advance,
    Nirmal Kumar Bhogadi.

    HI Nirmal,
    If u want to create the radiobuton and abutton according to the arraycollection data then u follow the following principle.
    Take a vbox. this is contains all the rasio button.
    then do a loop to the arraycolection upto it's length.
    and create the the radio button and add into vbox;
    ex
    <mx:Vbox id ="container"/>
    script:-
    privare var aa:arrayCollection =  ur arraycollection;
    private function addChild():void
         for(var i:int=0; i<aa.length; i++)
              container.addchild(new radioButton());
    I think this hint will help u. if u get ur answer please give me points
    Thanks
    Niranjan Swain

  • Adding text to a button, and related button fun

    Ok, I'm new to AS3 (only been doing it for a couple weeks
    now, never really learned AS2), so help would be great, especially
    as the deadline was more then a week ago (not all my fault there)
    I put a text field inside a button and tried to put text in
    that button's text field via the following:
    hmm.. I'm new to the forum I guess... don't know if it added
    the code, the code is: instancenameofbutton.textfieldinstance.text
    = "play";
    Well that seems not to work... so how do I make it obey my
    auth-or-a-tah?
    Am I perhaps just slash dot syntax impaired?
    Trouble seem to be that putting text over the button blocks
    the event.. Is there another way to skin this cat?
    A related problem I haven't been able to fix is.. I have a
    text field with dynamic text.. numbers, and I want it to be bold.
    Where I'm at in trying to figure out the solution is that bold
    dynamic text needs to be specially embedded.. Well, I follow what
    the help system tells me to do.. and nothing seems to actually
    work. Is there a bug here or something?
    Ok, one last related thing.. I'm following the book on
    "things thou shalt not do" in that I have a good amount of moving
    transparent gradients... well 2 of them actually.. but then other
    transparent stuff all over the place that.. could be pushing things
    a little far. The frame rate's about 14 fps, screen size is only
    about 600x450, I am on an 8 core mac pro with a better then
    standard graphics card... seems to me that I've been able to get
    away with worse on older version of Flash on a G3 power mac bad in
    the day....
    Well when I tried to dynamically load mp3s, that's when
    things started going down hill! now buttons blink, sometimes aren't
    responsive at all.. I'm thinking maybe its that I've over laded the
    player and ought to think pulling back...
    I have on gradient spinning shape thing that I was
    controlling by actionscript using the enter frame thing.. when I
    disabled the code.. well things worked fine again... accept that
    one of my buttons stopped working.. which is mysterious... cause as
    far as I know the code wasn't touching that at all.. so I went back
    to buggy vill, cause at least then my buttons work! (most of the
    time).
    So the only thing I can think to try and do is to try and
    optimize stuff... the projects a bit of a rush job.. so it's "a
    little hack-e" ( well I confess that at my best things are probably
    "a little" hack-e, so this is really bad)
    So I'm thinking of just changing the code over to a timer
    thing, will that make it all groovy? I mean do you think? I seem to
    remember hearing something, somewhere, about the enter frame thing
    as having some issues somewhere...
    What's also kind of strange is that stuff gets strange when
    the mp3s are loaded.. There's only 4 of them, small little
    snippets.. which probably total only about 1MB or so.. so why
    should that make it trouble? Admittedly there's not a lot of
    compression on them, and there stereo but?
    Anyway.. I guess I'm just wondering if any of this sets of
    any red flags for anyone who actually knows what they are doing..
    probably not describing things well enough.. but you know, any help
    is appreciated :)

    same questions, same answers
    I'm new to AS3 too. I know the kind of frustration you face,
    especially when it comes to finding out the how's. So I'm giving
    answers rather than telling people where to look for them (for
    now).

  • APEX:How to put dynamic buttons in a Report.

    Hello all,
    I am creating one application in which i want two buttons in every record. I can't put it manually because it should change according to records in a table So Can anyone tell me how to put dynamic buttons in a report.
    Thanks & Regards,
    Jiten Pansara

    Hi Jiten,
    you cannot create buttons in the report, but you can always create link columns with some css class to show it as button.
    So in the both link column report attributes you will have class="button1" and class="button2"
    And in dynamic actions you need to bind the events based on your link column's jquery selector like:
    .button1
    .button2Thanks

  • How to create a dynamic button?

    Hi,
    I'm trying to find some information on how to create a button that can be used in a dynamic form within a flowable subform to duplicate that subfom if they need to add more information in that same format.
    I've been able to find information on flowable forms and static vs dynamic as well as the concept behind the button but i can't seem to find anywhere instructions on how to actually do it. What scripts to put in in order to get the outcome i'm trying to achieve, all i can find is stuff on the samples and because i can only open the PDF version of the sample and the dynamic version that i can't open i'm unable to see exactly how they've done that sample.
    Can anyone help me?????
    Any help would be appreciated.
    Thank you in advance.

    Hi Niall,
    Thanks again for your help. That has helped a little. My next drama is that i cannot figure out at all is to get it to follow onto the next page instead of immediately after the section i want to repeat. Everytime i change the Pagination settings i loose my content on that page that has the section on it. I don't know how to change those settings to make it work. Any clues???
    I am so close in getting it right that it's frustrating not being able to find the right setting. The scripting works on the buttons and i've worked that out but just can't seem to get that next step done. With this particular component of LC in creating a form, do you have to make the following fields/subforms to flow aswell so that it can move down the page???
    Thanks in advance.

  • Make the Dynamic button to be invisible in srm

    Hi Guys,
    Am working in the current requirement where i need to delete the dynamic buttons in the shopping cart screen in SRM 7,i have mentioned the button names below ...Please help me out.
    Buttons;
    1)System info
    2)Export
    3)Memory snapshot
    Thanks,
    Vignesh.

    Hi Vignesh ,
    go to tcode 80 in webdynpro /component : FPM_OIF_COMPONENT expand thei webdynpro component go to component  configuration folder -->go this configuration  : /SAPSRM/WDCC_FPM_OIF_PO_PURCH
    click on the start configurator
    on screen will open in browser
    in this screen
    click on  other function button
    click on this and create the enhancement , after creating enhancement then click on change  button
    in the screen you can find the export button click onit
    here you cab set the visibility as  invisible .
    Thanks & Regards
    Pradeep Kumar Dondeti

  • Radio buttons and SQL

    Hi,
    I have a column in my database called buy_or_share. I have
    the type set at ENUM ('buy', 'share') and default as: buy. I am
    building a search page for users to search whether they want to buy
    or share (in the form of a radio group) and then a search bar for
    the user to type into freely what product, category, or store name
    they are seeking.
    I have tried to attach dynamic radio feature to the buttons
    and I've also tried quite a few different ideas with the recordset,
    but nothing has worked. When I search for a product, I am given
    results of the product for both buy and share so obviously the
    radio group isn't separating the results to either buy or share.
    The trouble is that I don't know what I'm doing wrong, is it
    something with the radio group? the recordset? the dynamic form
    elements? my php code, should I have a conditional statement
    surrounding the buttons so that if 'buy' is true then retrieve the
    database for 'buy' else 'share' true then get that information,
    else neither are true display 'no results'?... Thank you for the
    help!
    I have attached the relevant code...
    Brad

    Hi,
    One way to achieve this would be to
    Create an Item 'Radiogroup (with Submit)' called PXX_RADIO and enter 'STATIC:SQL 1;1,SQL 2;2,SQL 3;3' in the List of values definition
    Create a region of type 'SQL Query (PL/SQL function body returning SQL query) and enter
    begin
    IF :PXX_RADIO = 1
    THEN
    return 'Select 1 from dual;';
    ELSIF :PXX_RADIO = 2
    THEN
    return 'Select 2,2 from dual;';
    ELSIF :PXX_RADIO = 3
    THEN
    return 'Select 3,3,3 from dual;';
    end if;
    end;
    Set the region to use 'Use Generic Column Names (parse query at runtime only)
    In the regions conditional display set condition type to 'Value of Item in Expression 1 is NOT NULL' and enter PXX_RADIO in Expression 1
    So depending on the value of the radiogroup the relevant SQL is executed.
    Hope this helps
    Regards
    Paul

  • Dynamic Forms and PDF Preview

    I'm new to PDF forms and designer. I have encountered 2 issues that I can't get around.
    1 - PDF Preview - When I go from "body pages" to "PDF Preview" it goes into a script saying it can't download from a website and errors out. I believe it worked properly for awhile. Is this normal ? I tried to reload and repair my acrobat, but to no avail.
    2 - I'm trying to create a dynamic form and there is very little info on creating a dynamic form and what info I have found is very evasive?
    I'm trying to create a form section that has line items. I would like to have the line items expand by an input, by the user. example: the user enters # items to order "6" and then six line items appear for the user to fill out

    Hello Dave,
    I can't say I've seen issue 1 before and would recommend contacting support.
    For item 2 I would suggest wrapping your 'line' of text in a subform then creating a script to use the setInstance method for that subform.
    Let's say you had a subform named "TextLine" (which contained a text field), a numeric field called "NumberOfLines" and a button called "SetLines". You would likely want to have javascript code on the SetLines button click event much like:
    TextLine.instanceManager.setInstances(NumberOfLines,rawValue);
    You will want to save this form as a Dynamic PDF before previewing and you will want to ensure that TextLine allows for more than one occurence (found under Object - Binding, Allow Subform to Repeat when you have that subform selected).
    You may also want to put in some validation against the NumberOfLines field to ensure it has a value.
    I hope that helps.

  • To get the input values from the dynamic tables and save in the SAPdatabase

    HI EXPERTS,
    I AM NEW TO WEB DYNPRO ABAP. MY QUERY IS HOW TO GET THE VALUES THE USER ENTERS IN THE DYNAMIC TABLE AND SAVE THE SAME IN THE SAP DATABASE. I HAVE CREATED THE TABLES BUTTON EVERYTHING BUT I DONT KNOW THE CODE HOW TO DO. PLEASE HELP ME OUT.

    >
    vadiv_maha wrote:
    > HI EXPERTS,
    >
    > I AM NEW TO WEB DYNPRO ABAP. MY QUERY IS HOW TO GET THE VALUES THE USER ENTERS IN THE DYNAMIC TABLE AND SAVE THE SAME IN THE SAP DATABASE. I HAVE CREATED THE TABLES BUTTON EVERYTHING BUT I DONT KNOW THE CODE HOW TO DO. PLEASE HELP ME OUT.
    hi,
    1 there is one property OnAction of the button...
    2 So, in this event handler,you have to read the context node to which ur table is binded
    3 use the code wizard
    control+f7
    , and use the method
    get_static_attribute_table
    4 now u have got the vaues in internal table,so now as pointed in the previous reply, you can use the
    Update
    or
    Modify
    statement...
    regards,
    Amit

Maybe you are looking for