Programmatically enable/disable application scrollbars

Hi,
At present I need to modify some of our custom tools in LabVIEW 2010 to work on lower resolution screens. The automatic rescaling functionality is not really an option as it distorts most UI features. I have looked at adding a vertical/horizontal scrollbar to the application and this appears to do what I need reasonably well. Unfortunately for those who do have the high resolution screens, I don't really wish for the scrollbars to be enabled. Is there a way of programatically enabling/disabling the vertical or horizontal scrollbar of an application? I can see this being possible on the controls, but haven't found the option for the actual application.
Thanks in advance for any help you can offer.
Regards,
Shane 
Solved!
Go to Solution.

Hi!
I'm glad you sorted it out 
Regards,
Even
Certified LabVIEW Associate Developer
Automated Test Developer
Topro AS
Norway

Similar Messages

  • Disabled property: enable two Application Module functions

    I am using jdeveloper 11.1.1.5 and problem I am facing is:
    I want to call two different Application Module functions on one button click. Button is existing on .jspx. For that purpose I have to use Disabled property of button to enable the Application Module functions. Please tell me how to enable both of the functions by using the Disabled property of button.
    Thanks,
    Regards
    Muddasar Amin

    Hi Ashwin,
    Is this the problem only with Application module methods? Can you try with managed bean methods?
    Also, do you have this commandButton enclosed within <af:form>/<af:subform> ?
    Regards,
    Ansh

  • Enabling/Disabling Tabs on Tab Control in an *.EXE

    Hello,
    I've got a VI with a Tab Control. Within that VI, I programmatically enable
    and disable some of the tabs depending on user inputs. This VI functions as
    I want it to in the Labview environment, but when I use Application Builder
    to create an *.exe, the tabs remain in their default states. I am using
    Labview 6i. Any suggestions?
    Thanks,
    Peter

    This behavoir is fixed in Ver 6.02. You can download a free udate
    from NI.
    On Fri, 10 Aug 2001 13:36:33 -0700, "Peter T"
    wrote:
    >Hello,
    >
    >I've got a VI with a Tab Control. Within that VI, I programmatically enable
    >and disable some of the tabs depending on user inputs. This VI functions as
    >I want it to in the Labview environment, but when I use Application Builder
    >to create an *.exe, the tabs remain in their default states. I am using
    >Labview 6i. Any suggestions?
    >
    >Thanks,
    >
    >Peter
    >
    ===========================================================================
    Christopher Dubea Phone: (985) 847-2280
    Vice President of Engineering Fax: (985) 847-2282
    Moving Parts L.L.C. email: [email protected]
    P. O. Box 6117 URL: http://www.
    movingpart.com
    Slidell, LA 70469-6117

  • Enable/disable/defaulting the radio button in tabular Form

    Hi friends,
    I have one radio button column in my tabular form with 3 values for it.
    <li>FC
    <li>BC
    <li>EC
    I need to enable/disable the radio buttons according to the position of the user.
    If the position of the user is CEO means,
    then FC radio button has to be checked defaultly and also for him he needs to have BC and EC radio buttons to be enabled.
    If the position of the user is between(1-4) grades means,
    then FC radio button has to be disabled, but BC radio button has to be checked defaultly and also for him he needs to have EC radio buttons to be enabled.
    If the position of the user is between(4-6) grades means,
    then FC, BC radio button has to be disabled, but EC radio button has to be checked defaultly.
    How i can achieve this radio button enabling/disabling and defaulting it dynamically according to the user.
    Where i need to specify this kind of restriction inorder to work for me in my application.
    Brgds,
    Mini

    Hi Bob,
    thanks for your reply first, and your suggestion too.
    I tried in the below manner on the lov definition of my radio button and it hide/shown according to the user who logs into the application.
    SELECT 'FC' d, 'FC' r FROM DUAL WHERE lower(:APP_USER) = (select lower(user_name) from apps.xxhy_ams_details_v where upper(job_name) = 'CEO')
    UNION ALL
    SELECT 'BC' d, 'BC' r FROM DUAL WHERE lower(:APP_USER) IN (select lower(user_name) from apps.xxhy_ams_details_v where grade_name
    BETWEEN 1 and 4 OR lower(:APP_USER) = (select lower(user_name) from apps.xxhy_ams_details_v where upper(job_name) = 'CEO'))
    UNION ALL
    SELECT 'EC' d, 'EC' r FROM DUALBut how i can check the radio button defaultly according to the user who logs in .
    <li> If the employee with the position CEO logs into the application means, he needs to have FC to be checked defaultly.
    <li> If the employee with the grade between(1-4) logs into the application means, he needs to have BC to be checked defaultly.
    <li> If the employee with the grade between(5-12) logs into the application means, he needs to have EC to be checked defaultly.
    Note:
    Instead of hide/show the radio buttons defaultly whether it is possible to enable/disable the radio button according to the user who logs into the application.
    Brgds,
    Mini...

  • Enable/Disable Column in a Advanced Bean Table

    Hi,
    I have 2 columns that needs to be enabled/disabled on a standard oa page PO Lines summary page.
    I went through couple of blogs/forums and found 2 approaches :-
    Approach 1
    1) Extended the standard VO POLinesMerge.
    2) Added a attribute column DeriveDisplayFlag of type VARCHAR2 . This call a database function and will return Y or N
    3) Added a attribute of type ShowAdditionalColumn boolean. the get method of this attribute returns TRUE if DeriveDisplayFlag is 'Y' otherwise returns FALSE.
    4) created a substitution for the custom VO
    5) uploaded the substitution to mds.
    6) copied the xml/class files to $JAVA_TOP/..
    7) Bounced entire middle tier
    8) using personalization, entered a SPEL command on the rendered property. I know rendered will hide/show the column but for time being I just want this to work.
    But this fails :-
    oracle.apps.fnd.framework.OAException: Message not found. Application: FND, Message Name: FND_VIEWOBJECT_NOT_FOUND. Tokens: VONAME = XXPBPoLinesMergeVO; APPLICATION_MODULE = oracle.apps.po.document.server.DocumentAM;
    I am not aware how to get around this. Can someone help please?
    Approach 2
    1) steps 1 to 6 from Approach 1.
    2) trying to extend controller class OrderLinesTableRNCO. But have couple of questions. This iis a advanced bean table so how should i reference individual record and the column that i need to disable/enable ?
    Conceptual questions
    Also, when i am entering a new record at what point in time the 2 new attribute will derive its value? the 2 attributes are dependent on the Item number column but i have not created a dependency between the attributes and Item# column.
    Will the controller logic fire for every column while i am entering a new record?
    Thanks.

    Hi Anil,
    Thanks for the response. I have given up that i will get reply on this post.
    I have done the substitution and upload the jpx to umsing importer.
    But you are correct may be i might have done something wrong. Can you please help me. I can send you the files if you can review and let me know it will be great.
    Also, will this approach work since PO Lines is a advanced bean table ?
    One of the experts suggested to use Bound values. I am not sure how to implement it though?
    I have went and told back to my business team that I am not able to do this so now they have asked me to enable/disable columns based on a dff value on po header. I thought this will be easier by extending the controller class on PO Lines table but that too is not working.
    Can you help me please ?
    Here is my code to extend the controller class :-
    package xxpb.oracle.apps.po.webui;
    import oracle.apps.fnd.common.VersionInfo;
    import oracle.apps.fnd.framework.webui.OAControllerImpl;
    import oracle.apps.fnd.framework.webui.OAPageContext;
    import oracle.apps.fnd.framework.webui.beans.OAWebBean;
    import oracle.apps.fnd.framework.webui.beans.message.OAMessageLovInputBean;
    import oracle.apps.fnd.framework.webui.beans.message.OAMessageTextInputBean;
    import oracle.apps.fnd.framework.webui.beans.table.OAAdvancedTableBean;
    import oracle.apps.fnd.framework.webui.beans.table.OAColumnBean;
    import oracle.apps.fnd.framework.webui.beans.table.OASortableHeaderBean;
    import oracle.apps.fnd.framework.webui.beans.table.OATableBean;
    import oracle.apps.po.document.order.webui.OrderLinesTableRNCO;
    public class XXPBOrderLinesTableRNCO extends OrderLinesTableRNCO
    public void processRequest(OAPageContext pageContext, OAWebBean webBean)
    super.processRequest(pageContext, webBean);
    OAAdvancedTableBean tableBean =
    (OAAdvancedTableBean)webBean.findIndexedChildRecursive("LinesTableRN");
    OAMessageLovInputBean poLineLov =
    (OAMessageLovInputBean)tableBean.findIndexedChildRecursive("XXPBSecondaryUOMLOV");
    poLineLov.setDisabled(false);
    }

  • Enable/disable textbox depending on list option, list is dependent on Radio

    Hi,
    I'm trying to enable/disable text_box which is dependent on select_list option, select_list is dependent on radio_button.
    I'm able to enable/disable select_list using radio_button options, but I'm unable to handle text box which is again dependent on this SELECT_LIST item.
    under html header page:-
    <script type="text/javascript">
    function disableOnValue(o)
    if (o.value == 'Y')
    document.getElementById('P86_Select_list_item').disabled = false;
    else
    document.getElementById('P86_Select_list_item').disabled = true;
    document.getElementById('P86_text_box_item').disabled = true;
    </script>
    <script type="text/javascript">
    $(document).ready(function()
    $('#P86_Select_list_item').change(function()
    if($(this).val() == 'Other')
    $('#P86_text_box_item').attr("disabled", false);
    else
    $('#P86_text_box_item').attr("disabled", true);
    </script>
    under Region_Source of the region, whose Display point :- <b>Before Footer</b>
    <script type="text/javascript">
    if(document.getElementById('P86_radio_button_0').checked == true)
    {disableOnValue(document.getElementById('P86_radio_button_0'));}
    else
    {disableOnValue(document.getElementById('P86_radio_button_1'));}
    </script>
    and under Radio_button item, HTML Form Element Attributes :- <b>onchange="javascript:disableOnValue(this);"</b>
    also same way under text_box item , HTML Form Element Attributes :- <b>disabled</b>
    any help
    Deep

    Thanks for replying Ben,
    I have kept an example into apex workspace
    workspace:- DEEPAPEX
    username:- [email protected]
    password:- walubu
    application "Javascript" page 1
    I'm able to enable/disable Select_list item & Text_box item with the help of Radio_button item(depending on user select yes or no option of the radio button)
    But after selecting Yes option of the radio_button, only when user select "Other" option of the Select_List item the Text_box should be enabled otherwise it should be disabled for any of the options of the Select_list item.
    I hope you understand my point.
    Deep

  • Enabling / Disabling graphs and opening a new Front Panel Window

    Hi,
      I have a simple application of showing 12 analog signals on 12 different graphs placed vertically in aligned position. I have to develop a user interface so that if user wants to display signal no. 1, 4 and 6 out of total 12 signals, he should make selection using check boxes and click a re-draw button. It should result in opening a separate window with these three signals displayed as separate graphs aligned vertically and adjusted to fit window size. Similarly later user can change his selection of displaying signals (from same acquired data) say 1, 3, 5, 6, 8, 9, 11 & 12 and click Redraw button. It should result in opening a new Window showing all these signals as separate graphs which are aligned vertically and resized to fit the window. Now I have two major issues in this context.
    1) I have been searching LabView help to locate a way to open a new window for this purpose but I failed to locate any way for it. As per my limited knowledge, it seems that we cannot have multiple "Front Panel" windows in Labview.
    2) For the graph I could not locate a control to enable/disable a graph so that it appears or vanishes. Is there any way to achieve it?
    I shall appreciate your valuable advice. I shifted from "Lab View Signal Express"  to "Lab View" in order to achieve this user interface design but I am still not successful in finding a good solution for this application.
    Regards
    Mnuet

    Hi Mnuet,
    You can do what was said above. Here is a KB on dynamically loading VIs. It looks something like this.
    Dynamically loaded VIs are loaded at the point in code while running, as opposed to being loaded when the parent VI is loaded into memory like normal subVIs. You can make a reference to them and then control the front panel appearance, their run status, etc with property nodes and invoke nodes.
    Jeff | LabVIEW Software Engineer

  • Need an enable/disable Labview VI for SC-2062 relay board using PCI-6503 DAQ Card.

    I am using Labview 6i, and I need to write an enable/disable VI that will enable and disable 6 of the 8 relays at any time while keeping the whole vi running. Therefore one or more positions may be changed at a time, but positions that don't change cannot be interrupted when changing others (no port resets allowed). I was wanting to maybe send a 1 by 6 array of some sort out but I can't figure out how to use the array to communicate with the DAQ card, relay board and SC-2051 adaptor. There also needs to be error handling in and out. Thanks for your help. Any examples would be very helpful.

    Hello;
    The best way to go about that is to disable the data points correspondent to the channels you want to disable. Meaning that you can ignore the datapoints of the channels you want to disable on the fly. That is the only way to disable channels on the fly.
    Regards
    Filipe A.
    Applications Engineer
    National Instruments

  • How to enable/disable the input fields based on the data entered/user action in the web dynpro abap?

    How to enable/disable the input fields based on the data entered in the web dynpro application abap?  If the user enters data in one input field then only the next input field should be enabled else it should be in disabled state. Please guide.

    Hi,
    Try this code.
    First create a attribute with the name readonly of type wdy_boolean and bind it read_only property of input field of which is you want to enable or disable.
    Next go to Init method.
    Set the readonly value as 'X'.
    DATA lo_el_context TYPE REF TO if_wd_context_element.
         DATA ls_context TYPE wd_this->element_context.
         DATA lv_visible TYPE wd_this->element_context-visible.
    *   get element via lead selection
         lo_el_context = wd_context->get_element( ).
    *   @TODO handle not set lead selection
         IF lo_el_context IS INITIAL.
         ENDIF.
    *   @TODO fill attribute
    *   lv_visible = 1.
    *   set single attribute
         lo_el_context->set_attribute(
           name =  `READONLY`
           value = 'X').
    After that Go to the Action  ENTER.
    First read the input field ( first input field, which is value entered field) , next give a condition
    if input value is not initial  then set the readonly value is '  '.
    DATA lo_nd_input TYPE REF TO if_wd_context_node.
         DATA lo_el_input TYPE REF TO if_wd_context_element.
         DATA ls_input TYPE wd_this->element_input.
         DATA lv_vbeln TYPE wd_this->element_input-vbeln.
    *   navigate from <CONTEXT> to <INPUT> via lead selection
         lo_nd_input = wd_context->get_child_node( name = wd_this->wdctx_input ).
    *   @TODO handle non existant child
    *   IF lo_nd_input IS INITIAL.
    *   ENDIF.
    *   get element via lead selection
         lo_el_input = lo_nd_input->get_element( ).
    *   @TODO handle not set lead selection
         IF lo_el_input IS INITIAL.
         ENDIF.
    *   get single attribute
         lo_el_input->get_attribute(
           EXPORTING
             name =  `VBELN`
           IMPORTING
             value = lv_vbeln ).
    if lv_vbeln IS not INITIAL.
        DATA lo_el_context TYPE REF TO if_wd_context_element.
        DATA ls_context TYPE wd_this->element_context.
        DATA lv_visible TYPE wd_this->element_context-visible.
    *  get element via lead selection
        lo_el_context = wd_context->get_element( ).
    *  @TODO handle not set lead selection
        IF lo_el_context IS INITIAL.
        ENDIF.
    *  @TODO fill attribute
    *  lv_visible = 1.
    *  set single attribute
        lo_el_context->set_attribute(
          name =  `READONLY`
          value = ' ' ).

  • Enable disable linkbar links in datagrid itemrenderer.

    Hi All,
    I have to show the linkbar in datagrid column as a renderer and enable and disable the links according to attached documents codes.
    here are my sample code
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init();">
    <mx:Script>
        <![CDATA[
            import mx.collections.ArrayCollection;
            [Bindable]
              public var arrColl:ArrayCollection = new ArrayCollection();
              public function init():void{
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
                  arrColl.addItem(["1,2,3","1,2"]);
                  arrColl.addItem(["1,2,3", "1,3"]);
        ]]>
    </mx:Script>
        <mx:DataGrid id="dg" dataProvider="{arrColl}" width="200" height="500" x="510" y="168" >
            <mx:columns>
                <mx:DataGridColumn  itemRenderer="assets.components.linkbarItemRenderer"  />   
            </mx:columns>
        </mx:DataGrid>
    </mx:Application>
    My item renderer linkbarItemRenderer.mxml as
    <?xml version="1.0" encoding="utf-8"?>
    <mx:HBox xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" creationComplete="init();" >
    <mx:Script>
        <![CDATA[
            import mx.controls.LinkButton;
            import mx.collections.ArrayCollection;
            import mx.controls.Alert;
            [Bindable] public var arrColl : ArrayCollection = new ArrayCollection();
            public var arrDocType : ArrayCollection = new ArrayCollection([{data:"1" , label:"AP"},{data:"2" , label:"AR"},{data:"3" , label:"BOL"}]);
            public var attDoccodes : Array;
            public function init():void
                try
                    var requiredDoc :String = data[0];
                    var attachDoc : String = data[1];
                    var reqDocCodes :Array =  requiredDoc.split(",");
                    attDoccodes = attachDoc.split(",");
                    if(reqDocCodes != null)
                        //add the links of required documents.
                        for(var i:int = 0 ; i<reqDocCodes.length; i++ )
                            var obj:Object = new Object();
                            for(var j : int = 0; j < arrDocType.length; j++)
                                if(arrDocType.getItemAt(j).data == reqDocCodes[i])
                                    obj.label = arrDocType.getItemAt(j).label;
                                    obj.data  = reqDocCodes[i];
                            arrColl.addItem(obj);
                    callLater(enableDisalbeLinks);
                catch(error:Error)
                    Alert.show("error ::"+error.getStackTrace());
            public function enableDisalbeLinks():void
                try
                    //disable all links first
                    for(var q:int=0; q< arrColl.length; q++)
                        LinkButton(linkBarId.getChildAt(q)).enabled = false;   
                    if(attDoccodes != null)
                        for(var k:int = 0; k<attDoccodes.length; k++)
                            for(var l:int = 0 ; l<arrColl.length; l++)
                                if(arrColl.getItemAt(l).data == attDoccodes[k])
                                    LinkButton(linkBarId.getChildAt(l)).enabled = true;   
                catch(error:Error)
                    Alert.show("error ::"+error.getStackTrace());
        ]]>
    </mx:Script>
            <mx:LinkBar id="linkBarId" dataProvider="{arrColl}" />   
    </mx:HBox>
    It renderes the link in correct form in datagrid first time.when i scroll the datagrid the rows are miss up with each other and links are not shown propers in enable/disable format.
    Thanks,
    Amol.

    Hi All,
    It was my fault. Got it work now.
    When I redirect to PR, it also calls my page initialization method and clear all data. I added a parameter and issue resolved.
    Thanks & Regards,
    KJ

  • Enable/Disable a ldap account programatically

    What I am trying to do is to enable/disable an account on iPlanet server through our application using LDAP API.
    I know that I have to set a value to nsaccountlock operational attribute to activate/inactivate the account. However, I looked at the inactive Perl script on the server and it seems to add nsRoleDN and nsRole to this account as well.
    Now I could do the same thing as the Perl script on my appliation, but my question is how do I know which Role do I use to add to the account I want to enable/disable? I know that the default role is nsManageDisableRole, but how about the admin change this Role name or using different role? Is there a way to detect the role?
    Thanks

    You cannot change the role name. If you want to use the same account activation scheme as used by the console and the perl script command lines, you must use the exact same names for roles, etc.
    If you don't care about using the console or the command lines to manage roles, you can use any scheme you like, but you cannot mix and match the two schemes.

  • Enable/disable buttons

    Hi All
    I have created an application wherein datablock is supposed to display 5 records at a time. In addition to it i have displayed 5 buttons alonside these records. But all the buttons are addresed by single name.
    I want to change the enable/disable property of the button in such a way that only those buttons get disabled where records value match with those given by me in procedure.
    Since all the buttons are having same name i am not able to target button corresponding to specific record.
    I will make the problem more clear:
    This is how my GUI looks
    Record1.element1 Record1.element2 Button1
    Record2.element1 Record2.element2 Button1
    Record3.element1 Record3.element2 Button1
    Record4.element1 Record4.element2 Button1
    Record5.element1 Record5.element2 Button1
    I want to disable button1 only corresponding to the record3.
    Can anyone help me out in this regard?

    Thanks Roel for your reply. I had already designed the way you mentioned(by using 1 button) but this is not the way application should look.
    Also I have to work on this application using designer only, that is the reason i have posted it in Designer forum so that i could get any clue as to how i have to proceed using designer.

  • How do we programmatically "enable" the Page to have

    Some body known how do we programmatically "enable" the Page to have
    Item level security. - analogous to checking the box in the Page edit mode for "Enable item level security"
    J.

    Try this. It might work for you.
    declare
         l_page portal.wwsbr_api.page_record;
    begin
         select * into l_page
         from portal.wwv_user_owned_corners
         where siteid = <page group id>
         and id =<page id>;
         -- 0 is disabled . 1 is enabled.
         l_page.haveitemsecurity := 1;
         portal.wwsbr_api.modify_folder(
                   p_page => l_page
         wwpro_api_invalidation.execute_cache_invalidation;
         commit;
    end;
    regards
    Suresh.

  • What should I do on an ECC system in order to enable external application a

    What should I do on an ECC system in order to enable external application access an sap table?
    Also what documentation should I give to external application developer in order to access SAP table with it?

    Hi jan,
    We access SAP information externally with remote-enabled RFCs.  One of your programmers would need to write the RFC to pull the information from SAP.  And the application at the other end would need to be written to call the RFC and receive the information.  This can be accomplished with a .NET connector (assuming you are connecting via a .NET project).  You will also need to create a username for the .NET project to use to connect, but I would recommend disabling GUI access, so that the person using .NET can only access information accessible through RFCs (which is controlled by the ABAPers).
    Let me know if you have any questions.
    SL

  • Enabling/Disabling menuitems in a JMenu

    Hi,
    The application I'm developing has a JMenu, like any other Swing app
    out there. The menuitems in that JMenu are enabled/disabled according
    to the state of the app. I'd like to know which is the best way to
    enable or disable the individual JMenuItems from any point in the
    app, do I have to hold a global pointer to every JMenuItem in the
    app and call setEnable() ? Or can I send a change event which
    is captured by a hypothetical enablelistener registered in
    every menu item ?
    thanks in advance

    Okay, here's a skeleton of working with actions and a Document/Listener pattern.
    Here are the core classes:
    import java.io.*;
    import java.util.*;
    import javax.swing.*;
    public interface DocModel {
        public class Event extends EventObject {
            public enum Type {DOC_OPENED, DOC_CLOSED};
            public Event(DocModel model, Type type) {
                super(model);
                this.type = type;
            public final Type getType() {
                return type;
            private final Type type;
        public interface Listener extends EventListener {
            public void docOpened(Event event);
            public void docClosed(Event event);
        public void addDocListener(Listener l);
        public void removeDocListener(Listener l);
        public void open(File file) throws IOException;
        public void play();
        public void close();
        public JComponent createView();
    }You don't have to nest types, but I like to.
    Here is an abstract class the lets EventListenerList do all the work (I copyied and pasted the code from the API.)
    import java.io.*;
    import javax.swing.event.*;
    public abstract class AbstractDocModel implements DocModel {
        private EventListenerList listenerList = new EventListenerList();
        protected void fireDocOpened() {
            Object[] listeners = listenerList.getListenerList();
            Event evt = new Event(this, Event.Type.DOC_OPENED);
            for (int i = listeners.length-2; i>=0; i-=2) {
                if (listeners==Listener.class)
    ((Listener)listeners[i+1]).docOpened(evt);
    protected void fireDocClosed() {
    Object[] listeners = listenerList.getListenerList();
    Event evt = new Event(this, Event.Type.DOC_CLOSED);
    for (int i = listeners.length-2; i>=0; i-=2) {
    if (listeners[i]==Listener.class)
    ((Listener)listeners[i+1]).docClosed(evt);
    public void addDocListener(Listener l) {
    listenerList.add(Listener.class, l);
    public void removeDocListener(Listener l) {
    listenerList.remove(Listener.class, l);
    public void open(File file) throws IOException {
    fireDocOpened();
    public void close() {
    fireDocClosed();
    Here is a simple implementation with Actions. I didn't have to make the actions DocListeners as well --
    that's overkill, I could have adjusted their enabled state in open/play/close, but I wanted to demonstrate
    letting listeners keep themselves in synch.
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.text.*;
    public class SimpleDocModel extends AbstractDocModel {
        private Document document = new PlainDocument();
        private class OpenAction extends AbstractAction implements DocModel.Listener {
            public OpenAction() {
                super("open");
            public void actionPerformed(ActionEvent evt) {
                try {//find file
                    File file = new File("bogus");
                    open(file);
                } catch (IOException e) {
                    //report it...
            public void docOpened(Event event) {
                setEnabled(false);
            public void docClosed(Event event) {
                setEnabled(true);
        private OpenAction openAction = new OpenAction();
        private class PlayAction extends AbstractAction implements DocModel.Listener {
            public PlayAction()
            {   super("play");
                setEnabled(false);
            public void actionPerformed(ActionEvent evt) {
                play();
            public void docOpened(Event event) {
                setEnabled(true);
            public void docClosed(Event event) {
                setEnabled(false);
        private PlayAction playAction = new PlayAction();
        private class CloseAction extends AbstractAction implements DocModel.Listener {
            public CloseAction()
            {   super("close");
                setEnabled(false);
            public void actionPerformed(ActionEvent evt) {
                close();
            public void docOpened(Event event) {
                setEnabled(true);
            public void docClosed(Event event) {
                setEnabled(false);
        private CloseAction closeAction = new CloseAction();
        public SimpleDocModel() {
            setMessage("empty doc");
            addDocListener(openAction);
            addDocListener(playAction);
            addDocListener(closeAction);
        public void addToToolBar(JToolBar tb) {
            tb.add(openAction);
            tb.add(closeAction);
            tb.add(playAction);
        public void open(File file) throws IOException {
            setMessage("file opened");
            super.open(file);
        public void close() {
            setMessage("closed");
            super.close();
        public void play() {
            setMessage("playing continuously");
        public JComponent createView() {
            JTextField view = new JTextField();
            view.setDocument(document);
            view.setEditable(false);
            return view;
        private void setMessage(String message) {
            try {
                document.remove(0, document.getLength());
                document.insertString(0, message, null);
            } catch (BadLocationException e) {
                e.printStackTrace();
    }Are you still with me? Run this code:
    import java.awt.*;
    import javax.swing.*;
    public class SampleApp {
        JFrame frame = new JFrame("Sample App");
        SimpleDocModel model = new SimpleDocModel();
        public SampleApp () {
            JToolBar tb = new JToolBar();
            model.addToToolBar(tb);
            Container cp = frame.getContentPane();
            cp.add(tb, BorderLayout.NORTH);
            cp.add(model.createView(), BorderLayout.SOUTH);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        public static void main(String[] args) {
            new SampleApp();

Maybe you are looking for

  • Copy specific mail from one startup disk Mail to another copy of Mail?

    I booted from an external drive for a couple of days and read my email. Now I'm finding that my ISP has already deleted my email from its servers so I can't redownload it to my primary internal drive Leopard installation. I need to be able to get som

  • Bat.file in background

    i want to hav a bat. file (matrix) as a background in windows. how do i do it, or should i save the matrix as another format/type? here is the matrix file: @echo off pause color A mode 1000 :matrix echo %random%%random%%random%%random%%random%­%rando

  • How can I create a blog?

    How can I create a blog?

  • Need help with LG Cosmos touch please ? :)

    I have the LG Cosmos touch and I was wondering about something........When you view your messages from a person it shows a little blank avatar next to every message. You can go to pictures and set a contact ID for any of your contacts and so in messa

  • Workflow in PP

    Hi Friends, i have done workflow for PP, but i need the to trigger work flow for a specific plant only and for specific production order type only. i.e for each plant and order type work flow have to delivered for specific persons ( different persons