• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

enabling & disabling menuitems

 
Ranch Hand
Posts: 47
C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you already tried calling setEnabled(false) and setEnabled(true)? These should work for just about any component, including menus and menu items.
 
pankaj saxena
Ranch Hand
Posts: 47
C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 47
C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 47
C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
reply
    Bookmark Topic Watch Topic
  • New Topic