aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes enabling & disabling menuitems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "enabling & disabling menuitems" Watch "enabling & disabling menuitems" New topic
Author

enabling & disabling menuitems

pankaj saxena
Ranch Hand

Joined: Nov 21, 2009
Posts: 46
I am developing one project that has one Menubar that contains following Menu & each Menu then contains some MenuItems :
Menu are:
1. Enter Records.
2. Candidate's Status.

"Enter Records" Menu contains following MenuItems :
1. PersonalDetails
2. Enter Marks.
3. Cut-off.

"Candidate's status" Menu contains following MenuItems:
1. Search Status.
2. Debarred List.


Each Menuitems is a Panel(i.e a page, to input some details & do other works)

My question is :
Q: When I am displaying the "PersonalDetails" page , I am unable to disable other MenuItems(example "Enter Marks","Cut-off","Search status","Debarred List"), so that the user can't acces other Menuitems while using one page(menuitems).

Q: After completing task on one page (example , PersonalDetails), how can i enable other menuitems , so that every menuitem can be accessed.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

Have you already tried calling setEnabled(false) and setEnabled(true)? These should work for just about any component, including menus and menu items.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
pankaj saxena
Ranch Hand

Joined: Nov 21, 2009
Posts: 46
sir,

I have already used setEnabled() method , but the case is , it is disabling all menuitems but when i call setEnabled(true) then it is not enabling the menuitems.

Moreover, my class hierarchy is like as follows:

1. Module.java : it is a frame that contains two Panels , one panel contains Menubar while second panel is emtpy which i am using to display each page( a panel to take user input) by clicking on menuitem(eg. PersonalDetails).

2. I am declaring , initializing all menuitems in Module.java and on its menuitem click event i call "PersonalDetails.java" and there itself , i disable other menuitems. So far, its working as per me. But, on the display of PersonalDetails class, which contains a GUI form and a "Close "button . On "Close " button event handling i have called setEditable(true) on each menuitem.

It is throwing NullPointerException , since the PersonalDetails class doesn't have anything related to Menuitems, so i want to ask how should i move forward. Do i need to write one Utility class or something else.

thanks.
pankaj saxena
Ranch Hand

Joined: Nov 21, 2009
Posts: 46
Rob Prime wrote:Have you already tried calling setEnabled(false) and setEnabled(true)? These should work for just about any component, including menus and menu items.


sir,

I am sending the code of my classes:
1. Module.java
2. PersonalDetails.java
3. DefaultPage.java (this is just an empty page to be displayed at first)

My Questions are:

1. I want to write the code of enabling all or some menuitems in "close" button of PersonalDetails.java at line number 247 and can i write the same coding to enable and disable the menuitems in DefaultPage.java

2. In PersonalDetails.java class, I am unable to use JScrollPane appropriately and if somehow i am able to display the scrollbar, scrollbar is not working at all.

My codes are:

Module.java



PersonalDetails.java



DefaultPage.java





thanks.
pankaj saxena
Ranch Hand

Joined: Nov 21, 2009
Posts: 46
Rob Prime wrote:Have you already tried calling setEnabled(false) and setEnabled(true)? These should work for just about any component, including menus and menu items.


Sir,
I have solved the problem of scrollbar. but enabling menuitems are still left. Well, I am searching on it.

thanks.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19556
    
  16

The only place where you call setEnabled is in the handling of clicks on the Personal Details menu item. In this handling you only enable controls if that menu item is selected. However, regular menu items never are selected. The isSelected method isn't actually meant for regular buttons and menu items but for check boxes, radio buttons and check box menu items. In this case, personalmenuItem.isSelected() will always return false and that's why nothing is re-enabled. If I change the initialization of personalmenuItem to be a JCheckBoxMenuItem I can re-enable the other menu items. That's because for JCheckBoxMenuItem, isSelected() will return a different value if the menu item is selected (is checked).

Oh, and please PostRealCode next time. I had to make quite a few fixes because you have odd line breaks in some lines, especially in comments.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36579
    
  16
Rob Prime wrote:. . . Oh, and please PostRealCode next time. I had to make quite a few fixes because you have odd line breaks in some lines, especially in comments.
You also had so muchon one line, even several statements without line breaks, the whole thing was illegible. i have had to make lots of fixes too
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: enabling & disabling menuitems
 
Similar Threads
Table Structure(s)
Clarification for jstl <c:foreach> tag
Generics, arrays, and sorting
enabling & disabling menuitems
Java Assignment