Re: [NetBeans]changing menuitems



RedGrittyBrick wrote:

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?
Sorry what do you mean here ?
if so why not make a static method enableMenuItem(SomeClass someID,
boolean enabled)?
This is an idea
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?
ok this is a very interesting approach but how to implement a Listener in
GenListView that would intercept call from any other instances ?

Now a more general question : when using NetBeans you get help from the gui
to basically fabricate all graphic components but now when you have to
develop your own code is it possible and realistic to install it in the
same class.

I will have a look at the 2 websites you suggest.
Thanks.


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


.



Relevant Pages

  • [NetBeans]changing menuitems
    ... 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 ... public JMenuItem menuItem1; ...
    (comp.lang.java.help)
  • Re: [NetBeans]changing menuitems
    ... created by Netbeans I have menu items members with private status which ... means that oustide of any instances of "GenListView" NO WAY to simply ... public JMenuItem menuItem1; ... Maybe have GenListView implement a Listener and register itself as a listener to whatever class is changing the state that requires menu items to be disabled? ...
    (comp.lang.java.help)