Re: [NetBeans]changing menuitems
- From: RedGrittyBrick <RedGrittyBrick@xxxxxxxxxxxxx>
- Date: Fri, 25 Jul 2008 20:05:54 +0100
Daniel Moyne wrote:
I am using Netbeans and in my class "GenListView" where most of the code is
created by Netbeans I have menu items members with private status which
means that oustide of any instances of "GenListView" NO WAY to simply
change any of those menu items like desabling enabling them.
As I want to do this from a class that I will call hereafter "Other" not
included in GenListView this is what I did :
(a) in class "GenListView" I added this :
- in some methods :
menuItem1=jMenuItem1; //jMenuItem is declared as private by NetBeans
instance = this;
- these 2 methods :
public static GenListView getInstance() {
return instance;
}
public void enableMenuItem(JMenuItem menuItem) {
menuItem.setEnabled(true);
}
- these members :
static public GenListView instance;
public JMenuItem menuItem1;
(b) in class "Other" I added this :
- in some method :
GenListView.getInstance().disableMenuItem(GenListView.getInstance().menuItem1);
GenListView must be a singleton?
if so why not make a static method enableMenuItem(SomeClass someID, boolean enabled)?
Rather than telling GenListView what to do, maybe you should look at it the other way around and provide methods that allow you to tell GenListView about some external event, then let GenListView decide on appropriate changes to it's display.
I think you may need to disentangle your View from your Controller. Maybe have GenListView implement a Listener (of some sort) and register itself as a listener to whatever class is changing the state that requires menu items to be disabled? Maybe Actions would help too?
It works but looks complex to me ; any way to make it simpler as there is no
possibility for direct access of "jMenuItem1" from other class ?
Regards.
Elsewhere, Karsten Lentzsch recently suggested Fowlers essay. I think it might be useful in this context too.
http://martinfowler.com/eaaDev/OrganizingPresentations.html
I'd also read more about well-known design patterns and consider whether Interfaces, Enums etc would help. http://en.wikipedia.org/wiki/Design_Patterns#Behavioral_patterns
--
RGB
.
- Follow-Ups:
- Re: [NetBeans]changing menuitems
- From: Daniel Moyne
- Re: [NetBeans]changing menuitems
- From: Lew
- Re: [NetBeans]changing menuitems
- References:
- [NetBeans]changing menuitems
- From: Daniel Moyne
- [NetBeans]changing menuitems
- Prev by Date: [NetBeans]changing menuitems
- Next by Date: where is the java preferences file located
- Previous by thread: [NetBeans]changing menuitems
- Next by thread: Re: [NetBeans]changing menuitems
- Index(es):
Relevant Pages
|