Jump to content


Dropdownmenubutton


  • Please log in to reply
6 replies to this topic

#1 Draco

Draco

    Advanced Member

  • Members
  • PipPipPip
  • 819 posts
  • Gender:Male
  • Location:United Kingdom
  • Interests:Java duh...

Posted 08 May 2006 - 04:43 PM

Ok guys upon request from Buddybob from This Link
QUOTE
i feel u can post your answer in the "Tips and Tricks" subforums and help other members (including myself LOL   happy.gif ) on how to write a component like that. It wud be of tremendous benefit.

here is the so-so code to make this DropDownMenuButton (it really isnt anything special or hard to do, but it makes your GUI's look even better)

First off you need to have initialized your components including at least 1 JButton and 1 JPopupMenu  Also do not forget to add elements to your JPopupMenu

CODE
myJPopupMenu = new javax.swing.JPopupMenu();
myJButton = new javax.swing.JButton();
myJLabel = new javax.swing.JLabel("Inside PopupMenu");
//Add elements to the popupmenu
myJPopupMenu.add(myJLabel);

//Add more elements at your disposal

/*Next you need to add a mouseListener to myJButton that will be using the popupmenu
*
*Next comes the code for the mouseListener (which is really only one line of code unless you want more        
*Restrictions on it
*
*NOTE if you want just left click to work for this, you could just used actionPerformed on the button instead
*/
myJButton.addMouseListener(new java.awt.event.MouseAdapter()
{
  public void mouseClicked(java.awt.event.MouseEvent evt)
  {
    myJPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
  }
});

//Add all the other stuff you want


Thats all there is to display what I was wondering about.  If you want the elements within the JPopupMenu to do something when you click on them, just use actionPerformed method on the element.

I hope this helps someone (and hopefully what I have here makes sense);
-----------------------------------
Sun Certified Java Programmer
-----------------------------------
Java 1.5 API <---Check the specs
Google is your friend

#2 buddybob

buddybob

    Advanced Member

  • Members
  • PipPipPip
  • 452 posts
  • Gender:Male
  • Location:Bangalore
  • Interests:Java, Airplanes, Trance Music, Movies...blah blah

Posted 08 May 2006 - 04:49 PM

QUOTE(Draco @ May 8 2006, 10:13 PM) View Post

Ok guys upon request from Buddybob from This Link

here is the so-so code to make this DropDownMenuButton (it really isnt anything special or hard to do, but it makes your GUI's look even better)

First off you need to have initialized your components including at least 1 JButton and 1 JPopupMenu  Also do not forget to add elements to your JPopupMenu

CODE
myJPopupMenu = new javax.swing.JPopupMenu();
myJButton = new javax.swing.JButton();
myJLabel = new javax.swing.JLabel("Inside PopupMenu");
//Add elements to the popupmenu
myJPopupMenu.add(myJLabel);

//Add more elements at your disposal

/*Next you need to add a mouseListener to myJButton that will be using the popupmenu
*
*Next comes the code for the mouseListener (which is really only one line of code unless you want more        
*Restrictions on it
*
*NOTE if you want just left click to work for this, you could just used actionPerformed on the button instead
*/
myJButton.addMouseListener(new java.awt.event.MouseAdapter()
{
  public void mouseClicked(java.awt.event.MouseEvent evt)
  {
    myJPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY());
  }
});

//Add all the other stuff you want


Thats all there is to display what I was wondering about.  If you want the elements within the JPopupMenu to do something when you click on them, just use actionPerformed method on the element.

I hope this helps someone (and hopefully what I have here makes sense);


Thanks for considering my suggestion.

It really is a useful component. Gud effort!

P.S. Can u also please post a screenshot of the component inline on the forum?

Thank you very much again.  smile.gif
Best Regards,
Ranganath Kini
Sun Certified Java Programmer

#3 Draco

Draco

    Advanced Member

  • Members
  • PipPipPip
  • 819 posts
  • Gender:Male
  • Location:United Kingdom
  • Interests:Java duh...

Posted 08 May 2006 - 05:55 PM

QUOTE(buddybob @ May 8 2006, 12:49 PM) View Post

Can u also please post a screenshot of the component inline on the forum?


Hope this is what you mean:

IPB Image
-----------------------------------
Sun Certified Java Programmer
-----------------------------------
Java 1.5 API <---Check the specs
Google is your friend

#4 buddybob

buddybob

    Advanced Member

  • Members
  • PipPipPip
  • 452 posts
  • Gender:Male
  • Location:Bangalore
  • Interests:Java, Airplanes, Trance Music, Movies...blah blah

Posted 08 May 2006 - 06:56 PM

QUOTE(Draco @ May 8 2006, 11:25 PM) View Post

Hope this is what you mean:

IPB Image


WOW!!! Exactly!!! Hats off!

Awesome job there amigo!  wink.gif
Best Regards,
Ranganath Kini
Sun Certified Java Programmer

#5 Draco

Draco

    Advanced Member

  • Members
  • PipPipPip
  • 819 posts
  • Gender:Male
  • Location:United Kingdom
  • Interests:Java duh...

Posted 08 May 2006 - 08:04 PM

Thank you very much buddy

This will be my business's first released program.  Hopefully ppl will enjoy it
-----------------------------------
Sun Certified Java Programmer
-----------------------------------
Java 1.5 API <---Check the specs
Google is your friend

#6 buddybob

buddybob

    Advanced Member

  • Members
  • PipPipPip
  • 452 posts
  • Gender:Male
  • Location:Bangalore
  • Interests:Java, Airplanes, Trance Music, Movies...blah blah

Posted 11 May 2006 - 09:26 AM

QUOTE(Draco @ May 9 2006, 01:34 AM) View Post

Thank you very much buddy

This will be my business's first released program.  Hopefully ppl will enjoy it


Gud luck with that!  wink.gif
Best Regards,
Ranganath Kini
Sun Certified Java Programmer

#7 Pixel Z

Pixel Z

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 17 October 2010 - 09:04 PM

Nice job, thanks buddy   biggrin.giflaugh.gif
Winning is 2% skill, 98% attitude...

~ ˜°mohamadm96@sbcglobal.net°˜ ~