NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Dynamic custom JMenuBars

 
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users
View previous topic :: View next topic  
Author Message
fetchex



Joined: 19 Mar 2012
Posts: 1

PostPosted: Mon Mar 19, 2012 9:00 pm    Post subject: Dynamic custom JMenuBars Reply with quote

Hi folks, here's the thing:
I have 3 classes

1) LoginForm (JPanel)
2) MainForm (JPanel)
3) MenuSelector (Class)

And I want to SET the menu bar on MainForm depending of the user that logs on LoginForm. And the content of the menu is programmed in MenuSelector class.

LoginForm:

Code:
 private void button_accessMouseClicked(java.awt.event.MouseEvent evt) {                                           
        String user = field_id_operator.getText();
        int pool=50;
        char[] pass = field_password.getPassword();
        String pass2 = String.valueOf(pass);
        DBConnection db = new DBConnection(user, pass2, null);
        if (db.getStatus()){       
            try {
                MainForm.setLogin(user,pool);
                MenuSelector menu = new MenuSelector();               
                MainForm.setCustomMenu(menu);
                this.setClosed(true);
               
            } catch (PropertyVetoException ex) {
                Logger.getLogger(LoginForm.class.getName()).log(Level.SEVERE, null, ex);
            }
}


MenuSelector:

Code:
public class MenuSelector extends JMenuBar{
    static JMenuBar bar;
    JMenuItem op1,op2,op3,op4;
    JMenu menu;
   
    public void menuSelector(){
        op1 = new JMenuItem("Opcion 1");
        op2 = new JMenuItem("Opcion 2");
        op3 = new JMenuItem("Opcion 3");
        op4 = new JMenuItem("Opcion 4");
        menu = new JMenu("Databases");
        bar = new JMenuBar();
        menu.add(op1);
        menu.add(op2);
        menu.addSeparator();
        menu.add(op3);
        menu.add(op4);
        bar.add(menu);
    }
 }


This of course, doesn't work..
It kinda makes me trouble with static/non-static errors...
Any help? (If you need more info please let me know)
Thanks!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> NetBeans Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo