• 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
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

enabling menu items

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello all..
im building an MDI swing application..
ive got a jinternal frame called RegisterFrame with a jbutton.when i press that button..i need to disable some menu items on the main desktop pain..
can anyone help me about how to do that,..
here is a snapshot of the code.

MDIapplication.java
*****************************************************
MDI APPLICATION

package mainprogram
import register.*;
.
.
private javax.swing.JMenuItem alertMenuItem;
private javax.swing.JDesktopPane desktopPane;
private javax.swing.JMenuItem examresultsMenuItem;
private javax.swing.JMenuItem exitMenuItem;
private javax.swing.JMenu fileMenu;
private javax.swing.JMenuItem lecturenotesMenuItem;
private javax.swing.JMenuItem loginMenuItem;
private javax.swing.JMenuItem logoutMenuItem;
private javax.swing.JMenuBar menuBar;
private javax.swing.JMenuItem registerMenuItem;
private javax.swing.JMenu servicesMenu;

private void registerMenuItemActionPerformed(java.awt.event.ActionEvent evt) {
//call the jinternal frame ..located in another .java file

registerFrame frame=new registerFrame();
desktopPane.add(frame);
frame.moveToFront();
frame.setVisible(true);


}

RegisterFrame.java
******************************************

package register;

import mainprogram.*;

public class registerFrame extends JInternalFrame {

private JButton okRegistered;

public registerFrame(){


super("Registration",true,true,true,true);
okRegistered = new JButton();
setLocation(100,100);
setSize(500,500);
okRegistered.setSize(10,10);
okRegistered.setLocation(100,100);

getContentPane().setLayout(new FlowLayout());

getContentPane().add(okRegistered);

okRegistered.setText("OK");
okRegistered.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
okRegisteredActionPerformed(evt);
}
});
}


private void okRegisteredActionPerformed(ActionEvent evt) {
//when the user presses the button...one of the menuitems should be disabled...i cant figure out how to access the menu item login for example..i need to enable it

okRegistered.setText("Registration ok!!");

//how to enable the menu item??


}





----------
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
u want to diable some menuitem when u press the button and enable when u pressed a button

u have to use setVisible(boolean flag) method
or
u can also use setEnabled(boolean flag);

JMenuItem menuItm = new JMenuItem("Hide/unhide");
if u want to disable u use

menuItm.setvisible(false); / menuItm.setEnabled(false);



if u want to enable u use
menuItm.setvisible(true); / menuItm.setEnabled(true);

i hope now your problem is sorted out.Please Let me know which method u use
[ July 05, 2004: Message edited by: Ravi Lekhwani ]
 
Aboo Bolaky
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello Ravi..
i know these methods...but the problem is that he menuitems are in another java file and i cant find a way to call the appropriate method.u see what i mean?
mdiapplication.java contains the desktop pane, menu bar and menu items
registerframe.java contains the jinternal frame and an OK button. when i press the OK, i should disable some menu items found in the mdiapplication class
thnks!
 
Ranch Hand
Posts: 3178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course, you can pass the status of ok button from the registerframe class back to the caller class mdiapplication. I don't understand that much about the real requirement of your application, but I can see that OK button and menuitems arein different classes...

Of course, there are ways to send the status of your button back and forth the class... If you can provide the application and classes, it would be more likely that we can help you very effectively...
 
For my next trick, I'll need the help of a tiny ad ...
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic