Article View: borland.public.jbuilder.java.swing
Article #10483Disabling menuitems using Static Action class
From: hfl
Date: Sun, 12 Sep 1999 00:00
Date: Sun, 12 Sep 1999 00:00
63 lines
2502 bytes
2502 bytes
Here's a tricky one (I think):
Suppose you want to enable/disable menuitems not only within your frame, but
also in scripts of components that reside in your frame, but who's code may
be in a DIFFERENT package.
For example, certain nodes in a tree may require diabling of certain
menuitems. It is this code that I would like to include in the frame's class
code; not in the frame code. Seems reasonable, right?
Solution as I had it in mind: use "Static" to ensure the last menustatus
(enabled/disabled)
create a container class (for instance: FileSaveContainer) with a STATIC
Action attribute. Create a menuitem with:
new container (): in the constructor. An Action atribute will be created
that is returned by a method: getAction(), for example.
This Action object will be used to create the menuitem: MenuItem FileSave =
MainMenu.Add(Action)
Up until here everything's working fine!
Now: when I try to disable the menu with the following code:
Actioncontainer myContainer = new Actioncontainer ();
myContainer.theAction.setEnabled(false);
NOTHING HAPPENS!!!!
It's as if Actions don't like to be static or something...
Anyone any idea?
Thanx in advance!
here's a full code example:
public class BitAction extends Object {
public static Action sAction;
public BitAction() {
super();
}
public Action getAction() {
return sAction;
}
protected void setAction(Action aAction) {
sAction = aAction;
}
public void setEnabled(boolean aEnabled) {
Action lAction = getAction();
boolean before, after;
before = sAction.isEnabled();
getAction().setEnabled(aEnabled);
after = sAction.isEnabled();
}
}
Somewhere in the Frame:
BitActionAccept anAction = new BitActionAccept();
thisboolean = anAction.sAction.isEnabled(); -------->>>> This will
ALWAYS RETURN TRUE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
anAction.setEnabled(temp);
temp = !temp;
thisboolean = anAction.sAction.isEnabled();
henkf@gensec.com
Technical Details
Message-ID:
<7rg5a2$a273@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,f701970ebe6bd31c,start X-Google-Attributes: gid111d45,public From: "hfl" <henkf@gensec.com> Subject: Disabling menuitems using Static Action class Date: 1999/09/12 Message-ID: <7rg5a2$a273@forums.borland.com> X-Deja-AN: 524062804 Organization: Another Netscape Collabra Server User X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 Newsgroups: borland.public.jbuilder.java.swing