473,386 Members | 1,745 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

disabling and enabling MenuItems

daiyen
9
Hey there folks!

I need some help from you. I'm currently trying to refresh my memories of Java, thus I've decided to make a program using all my knowledge:) So far I've made a menubar, which contains some MenuItems in submenus, all of which are listened by the actionlistener interface. My problem is the following: I'd like to be able to use setEnabled() on each of my MenuItems after I've created them. I've tried to retrieve the Object that fires the event via actionevent, but apparently that's not the way I should have tried it. Any idea about where I should search for the answer?

Any help is appreciated!
Mar 9 '10 #1
2 1200
pbrockway2
151 Expert 100+
If want to do anything with the menu item after you have created it (like call setEnabled()) you will need to keep a reference to the item.

The Action interface provides a nice abstraction for this sort of thing. The idea behind it is that it is the action rather than any particular widget that is enabled or has properties like a description or mnemonic keys etc.

Construct the menu item using the constructor that takes an Action argument. You can then disable the action at any later time by using its setEnabled() method. But again you have to keep a reference to the action that you create.
Mar 10 '10 #2
daiyen
9
You're right and thank you for the help:) Although I forgot to mention the apparently important detail, that I'm using AWT rather than Swing, so I'm using MenuItem in stead of JMenuItem, which differs MenuItem in their constructors :( Is that possible that there's no way to solve this? I think I'm missing something very obvious, I'm just not sure what it is:)
Mar 11 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: sonic_soul | last post by:
Hello, I am finishing up creating a fairly complex page that is very rich in DHTML. In addition to updating it self every couple of seconds, various components on it support sync and async...
5
by: Lyn | last post by:
Hi, I hope someone can help. I have a main form which mostly fills the Access window. In the bottom half of this form I have a tab control to display various types of data related to the main...
0
by: Brian | last post by:
Create a simple MDI form and a child form, and try the following simple code to add a new menu item on the Edit menu popup: private void editMenu_Popup(object sender, System.EventArgs e) {...
2
by: HumptyDumpty | last post by:
Does anyone know if there is a problem with re-enabling the Screen Saver after it has been disabled programmatically. I am using the SystemParametersInfo function within User32.dll, and have...
2
by: adeelanjum2001 | last post by:
i am using radiolist box control in my page. when i disable radiolist box when page is displayed first time, that is not ispostback, and when i try to enable it with my javascript code afterwards,...
4
by: Rich P | last post by:
Greetings, I have a routine I was running in VB6 on a timed schedule. When the timeframe came up, the timer would be disable, the routine would run, and the timer gets enabled. I am trying to...
7
by: John Meyer | last post by:
I have a program where I have to enable or disable a list box based upon a radio button. Is there an "enabled" property on select boxes?
7
by: Vignesh | last post by:
I have tab control which has some TabPages. I want to enable or disable the tabpages based on some condition. It is possible to that. Thanks in advance.
2
by: dougawells | last post by:
Hi- I'm wanting to have a set of radio buttons disabled when a form is displayed, then if they check another specific radio button, those would become enabled. I've tried setting it via...
1
by: cravish | last post by:
Hi, I have an appliction in which,there are many User for whom different accesss right are given for different menuitem.Now, when a user Login in, he/she should have access to those many nos. of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.