Dynamically populating a JMenu

I'm new to Java, but was hoping someone could point me in the right direction for populating a menu with items as it is about to be displayed. This would be a cascading menu off a JMenu off a JMenuBar. I have figured out how to populate the JMenu, but don't know which hook to use to get notification that the user is about to display the cascading menu.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.Random;
public class Test extends JFrame {
  String[] nums = {"One","Two","Three","Four","Five","Six"};
  JMenu jm = new JMenu("Menu");
  Random r = new Random();
  public Test() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = getContentPane();
    JMenuBar jmb = new JMenuBar();
    setJMenuBar(jmb);
    jmb.add(jm);
    jm.addMenuListener(new MenuListener() {
      public void menuSelected(MenuEvent me) {
        jm.removeAll();
        for (int i=0; i<5; i++) {
          jm.add(new JMenuItem(nums[r.nextInt(nums.length)]));
      public void menuDeselected(MenuEvent me) {}
      public void menuCanceled(MenuEvent me) {}
    setSize(200, 200);
    setVisible(true);
  public static void main(String[] args) { new Test(); }
}

Similar Messages

  • Dynamically populating form -

    I need to make a dynamically populating form - I cannot find the instruction - is there a video on adobe tv? Please help me - I am desperate. Thanks a lot! K_S_

    Hi..
    I think you can do it with ADF .When you click field1 in your form get the value to bean using serverListner.And create method in AMImpl to filter records from TableB by passing your field1 value.make sure to add client interface to this filter method(clientInterface in yourAM.xml) and add it to page using bindings to as methodAction.Then you can show filtered TableB using popoup.

  • Dynamically populated parameter clears previously entered parameters

    Software: Crystal Reports XI with MS SQL Server 2008
    I've created a report that asks for three parameters, 2 dates, and a string which is dynamically populated. The report has two tables added in the database expert.
    The first table is a command object which passes the two date parameters to a stored procedure:
    exec sp_MyStoredProcedure {?startdate},{?enddate}
    The second table is a stored procedure object used to populate the string parameter {?_users}. The criteria for the string parameter are:
    Prompt with Description only: False
    Allow multiple values: True
    Allow discrete values: True
    Allow range values: False
    This stored procedure object requires no parameters, and was originally a view in the database, but it the same problem occurs whether i dynamically populate the string parameter options from either a view or a stored procedure. I'd like to go back to using a view, as i do not need to pass any kind of parameters to the stored procedure
    The string parameter is used for defining the record selection formula:
    IF {Command.user_name} in {?_users} THEN true ELSE false.
    The two tables are not linked in the database expert, but linking them does not seem to solve the problem I am having with this report, the problem being this:
    No matter which order I set the  parameters, it always first displays a form showing only the prompts for the date values. After entering these, it then shows a form prompting for the date values again (the previously selected date information now cleared), along with the list of users from which to select. On this 2nd form, the parameters are displayed in the order I set using the field explorer option presented when I right click on the Paramter Fields heading. After entering the date parameter values a 2nd time, and selecting the users from the  dynamically generated list, the report performs as intended.
    Edited by: Duraplex on Nov 12, 2010 6:26 PM
    Edited by: Duraplex on Nov 12, 2010 6:57 PM - After contacting the tech dept of my employer, they are applying a service pack update to my installation, I am hoping this resolves the issue. Will post an update as soon as I know more.
    Edited by: Duraplex on Nov 12, 2010 7:35 PM - After applying SP4 to my installation, the problem persists. I did note however that removing the string parameter and record selection formula, and then recreating them, does somewhat solve the issue temporarily - i still am presented with two forms, but the second form doesn't clear the previously entered date parameters. However,  once i save the report, and reload it, the problem manifests again and the date parameters are cleared when presented on the 2nd form. Has anyone else encountered a similar problem?
    Edited by: Duraplex on Nov 15, 2010 8:38 PM - Problem resolved by upgrading from Release 1 to Release 2.

    Hi,
    Once record status gets change for block you can not populate/repopulate the list item. Keep those list items as non-database item with different names and create different items as database orignal items. Than assign the values in WHEN-LIST-CHANGE trigger to the actual database items.
    -Ammad

  • Adding an override to enable a monitor for a dynamically populated group has no impact?

    Hello all,
    I have a monitor that I only want to target to a single computer group. The group is dynamically populated.
    My basic approach is that the monitor is disabled by default but enabled with an override for that group. However, the monitor does not appear to be running on those servers (or anywhere else). I was able to confirm this based on the results of running the
    "Show Running Rules and Monitors for this Health Service" task--the overridden monitor does not appear at all in the list of monitors running on the servers in that group.
    I have checked the Operations Manager event log on both the SCOM host and the machines in the group, and have not seen any errors. The monitor being overridden is a PowerShell script monitor, where for script logic issues I have seen that the event log will
    contain information on the error. Nothing appears anywhere to show that the monitor has been enabled for these servers.
    Is there a better way to determine why the monitors would not be running on the servers in the group?
    Thanks!

    Hey Gleb,
    I have validated that the group is being populated and that the monitor's target class matches the class of the group members.
    Checking today, it appears that the monitor has begun running on the members of the group... not sure why there was such a large delay before the monitor began executing on the servers. I still have the dreaded green circles in the health explorer, but have
    narrowed that down to a possible condition in my monitor's PowerShell script where the condition properties are not added to the PropertyBag before the script ends.
    Thanks!

  • Saving dynamically populated pdf forms

    We have forms developed in Live Cycle that are dynamically populated.
    We have extended these forms in Acrobat so that users may save them with the pre-populated data.
    Our issue is that the user must manipulate the form in some manner, such as changing a field, in order for it to be saved with the pre-populated data.
    Is there a way we can enable the user to simply open the form that has been dynamically populated and save it with this data simply by doing a "Save As"?
    Thanks in advance for any help offered~
    ~Chris

    > So, it appears that a server product is necessary to utilize and activate Reader Rights for users... Is this correct?
    No. Acrobat Pro 8 and 9 can activate certain rights, such as saving, which is what you said you did in your original post.
    Like I said earlier, the problem you're experiencing is odd, and may be related to the way the form was created in LiveCycle Designer or the way in which you are populating the form with data. If I were you, I would pose this question in a Designer-related forum. Include the details related to how the form is being dynamically populated. It would also be helpful to be able to look at a document in question.
    George

  • Dynamically populating List box

    Hello Everyone:
    I need to create a JSP with two combo boxes and submit button.
    Where the first combo box will be updated from database - which is simple.
    but depending on the selection of the first box the second box should be populated and should be able to make multiple selections in it.
    and in the same jsp page should be able to display the results, of what I added by submiting the previous form.
    Please can somebody help me witha sample.
    Thanks
    ASB

    Dear user,
    If you get any response for the asked question on Dynamically populating List box from anybody please forward the reply to the following e-mail id.
    [email protected]
    --SUBIR                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Dynamically populating more than one field using xml data binding

    Hi All,<br /><br />I have the following code that works fine to dynaically populate a<br />second drop-down list2 from a choice in drop-down list1 using xml data<br />biding.<br /><br />var tempString = "xfa.record." + this.boundItem(xfa.event.newText);<br />var oItems = xfa.resolveNode(tempString);<br />var nItemsLength = oItems.nodes.length;<br /><br />myinfo.page1.state.clearItems();<br />myinfo.page1.state.rawValue = null;<br /><br />for (var nItemCount = 0; nItemCount < nItemsLength; nItemCount++)<br />{<br />myinfo.page1.state.addItem(oItems.nodes.item(nItemCount).value);<br />}<br /><br />Here is my xml file<br /><br /><?xml version="1.0" encoding="UTF-8"?><br /><myinfo><br /><country/><br /><countries><br /><item uiname="United States" token="US"/><br /><item uiname="South Africa" token="SA"/><br /><item uiname="Australia" token="AU"/><br /></countries><br /><state/><br /><AU><br /><item>Australian Capital Territory</item><br /><item>New South Wales</item><br /><item>Northern Territory</item><br /><item>Queensland</item><br /><item>South Australia</item><br /><item>Tasmania</item><br /><item>Victoria</item><br /><item>Western Australia</item><br /></AU><br /><US><br /><item>California</item><br /><item>New York</item><br /><item>Texas</item><br /><item>Michigan</item><br /><item>North Carolina</item><br /><item>South Carolina</item><br /></US><br /><SA><br /><item>Eastern Cape</item><br /><item>Free State</item><br /><item>Gauteng</item><br /><item>KwaZulu-Natal</item><br /><item>Limpopo</item><br /><item>Mpumalanga</item><br /><item>Northern Cape</item><br /><item>North-West</item><br /><item>Western Cape</item><br /></SA><br /></myinfo><br /><br />I have two questions:<br /><br />1) I want to be able to structure my xml in a way that I can populate<br />a third drop-down list3 from a choice in list2. I need to know how to<br />to include the different capital cities of the states in my xml data<br />so that they can get populated in list3 from a selection in list2;<br /><br />2) And be able to script the third list3 to get dynamically populated<br />from a choice in list2.<br /><br />Thanks in advance for your help.

    I would like to ask someone for help.
    I have an XML file a result of the XSLT transformation. A schema was created based on this XML and this schema is bound to a form as a data source.  When I preview my form using a Preview tab with transformed XML as a Data File in LiveCycle Designer 8.1, I can see only the first form data across 3 Text fields on the form. The rest of the forms are not getting displayed. What am I doing wrong?
    Here is the part of the XML file Im trying to display on the form:
        FORM 1
        FORM 1 DESCRIPTION
        $5000
        FORM 2
        FORM 2 DESCRIPTION
        $7000
        FORM 3
        FORM 3 DESCRIPTION
        $4000
    Part of the schema that was created based on the XML file from above:
    Thank you.

  • Date parameter values cleared when dynamically populating string parameter

    Software: Crystal Reports XI Release 1 with SP4, with MS SQL Server 2008
    I've created a report that asks for three parameters, 2 dates, and a string which is dynamically populated. The report has two tables added in the database expert.
    The first table in the database expert is a command object which passes the two date parameters to a stored procedure:
    exec sp_MyStoredProcedure {?startdate},{?enddate}
    The second table in the database expert is a stored procedure object used to populate the string parameter {?_users}. The criteria for the string parameter are:
    Prompt with Description only: False
    Allow multiple values: True
    Allow discrete values: True
    Allow range values: False
    This stored procedure object requires nothing to be passed, it was originally a view in the database, but the same problem occurs whether i dynamically populate the string parameter options from either a view or a stored procedure.
    The string parameter is used for defining the record selection formula:
    IF {Command.user_name} in {?_users} THEN true ELSE false.
    The two table objects are not linked in the database expert, but linking them does not seem to solve the problem I am having with this report, the problem being this:
    No matter which order I set the parameters, it always first displays a form showing only the prompts for the date values. After entering these, it then shows a form prompting for the date values again (the previously selected date information now cleared), along with the list of users from which to select. On this 2nd form, the parameters are displayed in the order I set using the field explorer option presented when I right click on the Paramter Fields heading. After entering the date parameter values a 2nd time, and selecting the users from the dynamically generated list, the report performs as intended. After subsequently running the report  (prompting for new parameter values by pressing F5),  it does not clear the date parameters on the 2nd form's appearance.
    What I need is to be able to enter in these values the first time around, without having the date parameters cleared. Am i going about this incorrectly, or is this a bug?

    What you are experiencing is not a bug... Passing a multi-valued parameter to a Command or SP is not supported in any version of CR prior to CR 2008.
    Your options are #1) Upgrade to CR 2008 or #2) Jump through the necessary hoops to make it work in CR XI
    Check out this link...[SQL Command Parameter - Multiple Value|Re: SQL Command Parameter - Multiple Value]
    It has some good examples a good step by step.
    HTH,
    Jason

  • Paper form barcodes dynamically  populated

    The form has been Reader Enabled using LC RE,so how to dynamically populated by adobe reader?
    thanks.

    My code to access the firstName is here:
    public String selectCustomer() {
            logger.debug("Inside selectCustomer ()");
            FacesContext context = FacesContext.getCurrentInstance();
            CustomerProfileBean cpBean = customerProfileBean();
            String firstName = cpBean.getFirstName(); //First name is null here
            return "success";
        protected CustomerProfileBean customerProfileBean() {
            FacesContext context = FacesContext.getCurrentInstance();
            ValueBinding vb = context.getApplication().createValueBinding("#{CustomerProfileBean}");
            return (CustomerProfileBean) vb.getValue(context);
        }Scope is request...My question is - does h:outputLabel actually post back to the action?
    In the mean time, as a temporary ugly solution, I have done this:
    <h:outputLabel id="FirstNM"></h:outputLabel>
    <h:inputHidden id="FirstNMHidden" value="#{CustomerProfileBean.firstName}"></h:inputHidden>I populate both FirstNM and FirstNMHidden with javascript, where the first is used to display to the page and the second posts the value...Seems ugly?
    Thanks for your help.

  • Dynamically populated dropdown values are missing when instances are added

    HI Team
    I have a subform which is repeatable have  a drop down  as one of the field which is dynamically populated from the web service call(short lived process) from the DB.On initialize event of the subform the data connection is executed .Dropown is populated with the values but when an instance of subform is added the dropdown values are missing.
    Only in the first instance of a subform  dropdown values are showing up , when instances of subform is added the drop down values are missing.
    Please let me how can i solve this issue,
    Thanks in Advance
    Bharathi

    I've tried this option by adding some value (hard-coded) during initialize event of the subform and all values are populated in the newly added instances as well.
    Not sure why it's not working for you.. Can you try adding some sample values without calling web service and confirm if it's working?

  • Dynamically populating an XMLList

    How would i go about dynamically populating a specific node section with database values? See code below that is static. I'd like for example the Groups node to be populated with the names of groups in my database. I use Coldfusion as the server side language so I understand dataproviders but I cannot add a dataprovider in the node tag:
        <mx:XMLListCollection id="treeData">
            <mx:source>
          <mx:XMLList>
                  <node label="Items">
                      <node label="Open"/>
                      <node label="In Progress"/>
                      <node label="More Info"/>
                      <node label="Closed"/>
                  </node>
                  <node label="Categories">
                      <node label="Category 1"/>
                      <node label="Category 2"/>
                  </node>
                  <node label="Groups">
                      <node label="Group 1"/>
                      <node label="Group 2"/>
                      <node label="Group 3"/>
                  </node>           
                  <node label="Help"/>
          </mx:XMLList>
            </mx:source>
        </mx:XMLListCollection>

    oh, I'm really sorry for mistype, it should be like this:
    var groupsNode:XML = tree.descendants().(hasOwnProperty('@label') && @label == 'Groups')[0];

  • How to get values from dynamically populated field symbol

    Hi all,
    I am having a field symbol <fs_table> type standard table, which is getting populated dynamically.
    CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = i_fieldcat[]
        IMPORTING
          ep_table        = is_eptab.
      ASSIGN is_eptab->* TO <fs_table> .
    After the ALV display i am making some changes in the ALV and getting a new internal table <fst_table>,which is having changed values.
    Now the problem is that i am not able to get the changed values from <fst_table>  as it is not of any structure type and cant associate it with any field like we do in normal internal table and work areas like, wa-fieldname.
    All the fields are dynamic.
    Regards,
    Anant

    Hello Anant
    You have to access to access the fields of your dynamic outtab dynamically as well.
    DATA: ls_fcat   TYPE lvc_s_fcat.
    FIELD-SYMBOLS:
      <ls_struc>   TYPE any,
      <ld_fld>       TYPE any.
    LOOP AT <fs_table> ASSIGNING <ls_struc>.
      LOOP AT i_fieldcat INTO ls_fcat.
        ASSIGN COMPONENT ls_fcat-fieldname OF STRUCTURE <ls_struc> TO <ld_fld>.
        ...  " do processing
      ENDLOOP.
    ENDLOOP.
    Regards
      Uwe

  • Dynamically populating values in 2 dependent select in jsp

    hello users
    i am confronted with a probelm.
    i am having 2 select fields that are dependant on each other. i.e. select one and in the other select, values are automatically populated..
    the only problem here is that it has to be dynamically done
    i dunno javascript can do it dynamic ally but by hardquoting values, it can be done.(which obviously i dont want)
    i can't solve it by using arraylist or vector either. it may be i'm not using the correct method. but aneways, plz reply me asap
    thanks a lot in advance
    Rajeev

    hello sure
    thanx for taking the time to reply...i can email u my files there are 2 jsp files and 1 bean file ...u'll have to arrange them in a package (bean) under the folder WEB-INF if you are using tomcat..
    give me ur email id , i'll mail u the code in a zip format
    thanks once again
    Rajeev

  • Dynamically Populating Drop Down Lists

    Hi,
    I am trying to dynamically populate a drop down list on a form based on a selection in another drop down list. I have read the help file "To dynamically populate a second field after populating the first" which goes through an example, however I cannot get this example to work for me.
    I know that the best way to do it is to create an xml file and connect the form to this file. I am new to programming in xml but have had some experience in other forms. The code that I have (from the help page) looks like this;
    <?xml version="1.0" encoding="UTF-8"?>
    <MyData>
       <country/>
       <countries>
          <item uiname="United States" token="US"/>
          <item uiname="Vietnam" token="SRV"/>
       </countries>
       <state/>
       <US>
          <item>California</item>
          <item>New York</item>
          <item>Texas</item>
       </US>
       <SRV>
          <item>An Giang</item>
          <item>Bac Giang</item>
          <item>Bac Kan</item>
       </SRV>
    </MyData>
    I have then followed the instructions on the page, and am unable to populate either field on my form. Perhaps there is something wrong with my code? Or any other suggestions would be greatly appreciated! 
    Thanks

    Hi Paul,
    I have another question,
    I would now like to populate a third drop down menu based on the selection in the second one, however my code is going wrong somewhere as now when I put in the first 2 drop down lists, nothing appears in the second one. ie, the first drop down list I link to countries, and the second to state, as I did with the previous file, but now, when I preview it, I can choose a country, but nothing comes up in state. When I set the first drop down box to countries, I have to specify that I want it to show the uiname, but I can't do that with the second one when I select state using the XML file below, nothing is shown. Where am I going wrong?
    <MyData>
       <Country/>
       <countries>
          <item uiname="United States" token="US"/>
          <item uiname="Vietnam" token="SRV"/>
       </countries>  
       <state/>
       <US>
          <item uiname="California" token="CA"/>     
          <item uiname="New York" token="NY"/>   
          <item uiname="Texas" token="TEX"/>
       </US>
       <SRV>
          <item uiname="An Giang" token="AG"/>
          <item uiname="Ban Giang" token="BG"/>
          <item uiname="Bac Kan" token="BK"/>
       </SRV>
       <time/>
       <CA>
          <item>6</item>
          <item>7</item>
       </CA>
       <NY>
          <item>5</item>
          <item>4</item>
       </NY>
       <TEX>
          <item>3</item>
          <item>8</item>
       </TEX>
       <AG>
          <item>2</item>
       </AG>
       <BG>
          <item>1</item>
       </BG>
       <BK>
          <item>9</item>
       </BK>
    </MyData>
    Thank you for your help!

  • Dynamically Populated Option Sets in CRM 2013

    Hello,
    In my solution, I have an entity with an option set attribute that has no option values by default. A script in the entity form handles the population of the option set dropdown via .addOption. The displayed value of the attribute shows blank or "--"
    (for CRM 2013). The expected behavior is that when the user selects an item in the dropdown, the field value changes and then displays the selected value. Another attribute (single line of text) then gets that value for later use. This works just fine in CRM
    2011.
    However, in CRM 2013, selecting a value in the dropdown does not change the displayed value of the field. Putting focus again on the dropdown shows that the default value (blank) is selected (or nothing is selected).
    I tried to modify the field value using Xrm.Page/Entity and even JQuery directly on elements to at least to display the selected text, change some attributes, etc. None of this works. It should be noted that when attaching a "change" handler in
    JQuery to the dropdown, it fires. When specifying a change handler for the field in the form properties, it does not fire.
    I have another idea involving creating a workflow that runs periodically or another server process/plugin to dynamically populate a global option set, and then point my entity's option set attribute to that option set. If you're wondering why a workflow,
    the attribute is supposed to be a list of all existing entity names in the current default solution. If for some reason entities are added/removed from the solution, my option set needs to be brought up-to-date.
    Before going down this road, I'm wondering if any of you have encountered this and how you got around it.
    Thanks!

    Hello Mahender
    As Rod mentioned in his query, the option set attribute is supposed to be a list of all existing entity names in the current CRM organization . If for some reason entities are added/removed from the organization, the option set needs to be updated.
    Hence we created a blank option set attribute. Now, OnLoad of the form, we populate the option set using .addOption() method. This populates the option set, but on selection change, attribute's OnChange() is not getting triggered and also, the selected value
    is not visible on form.
    Below is an example of what we are trying to achieve
    http://www.powerobjects.com/blog/2012/01/25/microsoft-dynamics-crm-and-dynamic-option-sets/
    I hope I am able to explain my query in detail here.
    Any help is appreciated.
    Thanks,
    Bhavika Patel

Maybe you are looking for

  • IPhone calendar does not sync new events and appointments from Outlook

    iTunes 9.2.0.61/iPhone 4.0.1 - does not sync newly added events and appointments! Previously added stuff is all there, new stuff added in Outlook 2007 just doesn't show up. I've gone back to my old Palm T|X which syncs all this stuff with no problem,

  • Newer 32GB iPod Touch no longer connects to MacBook.

    My newer 32GB iPod Touch no longer connects to my MacBook at all. All has worked fine until yesterday.  All cables and USB port check out fine with older iPod. Touch still works beautifully but charge is dwindling. Since it's not recognized by MacBoo

  • My 2011 17in macbook pro is running slow with no hints as to why?

    Earlier this week I was playing a game on my windows partition and noticed it was incredibly slow so I went to the osx partition and it was slow there as well. By slow I mean when I type it takes awhile for the text to show up or changing from progra

  • DMG Not Recognized

    Just got a Macbook Pro running OS X 10.6.8 from my mom and for some reason I can't open some .dmg files. I downloaded a couple things and when trying open them it says it can't read the disc because the .dmg is not recognized. Right after that, my do

  • Urgent:Comparing file size and file hashcode

    Hi i am developing an EJB in which I have to dynamically pick the filename,filesize and hashcode of the file. In case filename exists then it should check for file size and hashcode of the file. if both of these are equal then the processing should s