• Post Reply Bookmark Topic Watch Topic
  • New Topic

JMenuItem disable on load

 
Pranav Kristam
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to disable one of the JMenuItem on load itself but when i tried with following code it is disabling after I selected the JMenuitem.


Please suggest me what additional changes are needed to make it work accordingly.

this.onOffItem = new JMenuItem("Filter");
this.onOffItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
applyTruthFlag(currentBTE.isTruthFlag());
}
});

this.menuFilter.add(this.onOffItem);

private void applyTruthFlag(boolean truthAuswertung) {
this.onOffItem.setEnabled(truthAuswertung);
//this.onOffItem.repaint();
}



Thanks
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Define "on load"
 
Pranav Kristam
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the reply. can you please elaborate with some more information or example, to which level on load method need to be defined.
 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To rephrase myself...What do you mean by 'on load'? When your component is visible? When your application starts? Anything else?
 
Pranav Kristam
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. Let me rephrase my requirement in this way: Based on some value one of the JMenu item should be disabled (grayed out) this is exactly what i need to be implement. With the above code snippet the JMenu Item is disabling after i select Jmenu item from JMenu, this is happening due to actionPerformed and invokes my method where I am disabling JMenuItem. But by default this JMenuitem should be disabled.

 
Maneesh Godbole
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pranav Kristam wrote: But by default this JMenuitem should be disabled.

In that case you can disable it when you initialize it.

 
Pranav Kristam
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your inputs. yes it's correct and working as expected after initialize I placed applyTruthFlag() method and moved out from actionPerformed()

this.onOffItem = new JMenuItem("Filter");
applyTruthFlag(currentBTE.isTruthFlag());
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!