How to create a button with the drop-down menu?

I want to create a button with the drop-down menu, which is like the 'back' on the tollbar in IE. I heard JPopupMenu can reach the certain result, but the button hadn't a down arrow. Who can help me?

i have made something like this :
//======================================================================
package com.ju.guiutils
import java.awt.*;
import java.awt.event.*;
import java.net.URL;
import java.util.Vector;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
import javax.swing.plaf.basic.BasicComboBoxUI;
* @version 1.0 14/04/02
* @author Syed Arshad Ali <br> [email protected]<br>
* <B>Usage : </B> ButtonsCombo basically performs function button + JComboBox, if we have different options for
* <BR>same button then we can use this ButtonsCombo.
*<BR> By the way there is no button at all in <I>ButtonsCombo</I>
public class ButtonsCombo extends JComboBox {
//===================================================================================
* Create ButtonsCombo with default combobox model
public ButtonsCombo () {
super ();
init ();
//===================================================================================
* Creates a ButtonsCombo that takes it's items from an existing ComboBoxModel.
public ButtonsCombo ( ComboBoxModel model ) {
super ( model );
init ();
//===================================================================================
* Creates a ButtonsCombo that contains the elements in the specified array.
public ButtonsCombo ( Object [] items ) {
super ( items );
init ();
//===================================================================================
* Creates a ButtonsCombo that contains the elements in the specified Vector.
public ButtonsCombo ( Vector items ) {
super ( items );
init ();
//===================================================================================
private void init () {
setBorder ( BorderFactory.createBevelBorder ( BevelBorder.RAISED ) );
setRenderer ( new ComboRenderer() );
setUI ( new ComboUI() );
addMouseListener ( new ComboMouseListener() );
//===================================================================================
* Set items for ButtonsCombo in the specified array
public void setItems ( Object [] items ) {
setModel ( new DefaultComboBoxModel( items ) );
//```````````````````````````````````````````````````````````````````````````````````
* Set items for ButtonsCombo in the specified Vector
public void setItems ( Vector items ) {
setModel ( new DefaultComboBoxModel( items ) );
//```````````````````````````````````````````````````````````````````````````````````
* Get current items in a array
public Object [] getItemsArray () {
ComboBoxModel model = this.getModel ();
if ( model != null ) {
int size = model.getSize ();
if ( size > 0 ) {
Object [] items = new Object[ size ];
for ( int i = 0; i < size; i++ ) {
items[ i ] = model.getElementAt ( i );
return items;
return null;
//```````````````````````````````````````````````````````````````````````````````````
* Get current items in a Vector
public Vector getItemsVector () {
ComboBoxModel model = this.getModel ();
if ( model != null ) {
int size = model.getSize ();
if ( size > 0 ) {
Vector itemsVec = new Vector();
for ( int i = 0; i < size; i++ ) {
itemsVec.addElement ( model.getElementAt ( i ) );
return itemsVec;
return null;
//===================================================================================
class ComboMouseListener extends MouseAdapter {
public void mouseClicked ( MouseEvent me ) {
ButtonsCombo.this.hidePopup ();
public void mousePressed ( MouseEvent me ) {
ButtonsCombo.this.hidePopup ();
ButtonsCombo.this.setBorder ( BorderFactory.createBevelBorder ( BevelBorder.LOWERED ) );
public void mouseReleased ( MouseEvent me ) {
ButtonsCombo.this.hidePopup ();
ButtonsCombo.this.setBorder ( BorderFactory.createBevelBorder ( BevelBorder.RAISED ) );
//===================================================================================
class ComboRenderer extends JLabel implements ListCellRenderer {
//````````````````````````````````````````````````
public ComboRenderer () {
setOpaque ( true );
//````````````````````````````````````````````````
public Component getListCellRendererComponent ( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus ) {
setBackground ( isSelected ? Color.cyan : Color.white );
setForeground ( isSelected ? Color.red : Color.black );
setText ( ( String )value );
return this;
//````````````````````````````````````````````````
//===================================================================================
// We have to use this class, otherwise we cannot stop JComboBox's popup to go down
class ComboUI extends BasicComboBoxUI {
public JButton createArrowButton () throws NullPointerException {
try {
URL url = getClass ().getResource ( "/images/comboarrow.gif" );
JButton b = new JButton( new ImageIcon( url ) );
b.addActionListener ( new ActionListener() {
public void actionPerformed ( ActionEvent ae ) {
return b;
} catch ( NullPointerException npe ) {
throw new NullPointerException( "/images/comboarrow.gif not found or /images folder not in classpath" );
catch ( Exception e ) {
e.printStackTrace ();
return null;
//======================================================================
you can cutomize this according to your requirement , okie ;)

Similar Messages

  • Need help on creating a button with additional drop down menu

    Hi,
    I need to have a button with additional menu as we see in IE, please help me how can i do that. I want the button to be displayed normally with an additional arrow on the right side when clicked on it shows pop up menu. Please let me know if the solution has already there in the forum. I searched and couldn't get one .. :(

    Hey there buddy.
    Try this:
    http://www.koders.com/java/fid20361AB8C305DE9B9110DE90F2154FC43AA0E57C.aspx
    Jason.

  • I don't see the new "firefox button" and i can't see the bookmark button (with the drop down option) unless I'm in the customize toolbar view. How can I fix these?

    I am using Firefox 4.0 on Windows XP home, Service pack 3. I am trying to use some of the new features of Firefox 4.0 that I see on the Firefox feature page (http://mzl.la/gCFDjj) and am not having much luck. First off in the Firefox Button. It is supposed to contain all your menu items but it is not appearing on my screen. Is this a feature that only works in Vista or Windows 7?
    Second, I am trying to use the Bookmarks Button (the one that has the drop down menu) but it doesn't appear in my toolbar unless I right click the tool bar and choose "customize". The button shows up in this view already in the toolbar, as if it is hidden in normal use and no matter where I move it to, once I hit the "done" button in the customize window the Bookmarks Button gets hidden/covered up again.
    Third, I see the new "App Tabs" feature but I can't seem to find an option for this in the preferences for Firefox, if it's even supported by my browser/OS at all.
    Can anyone tell me how to use/activate these features or if I am even able to using Windows XP?

    You see the orange (on Linux gray) Firefox button if the Menu Bar is hidden (View > Toolbars > Customize or right-click a toolbar).<br />
    If you need to access the hidden Menu bar then press F10 or hold down the Alt key to make the Menu Bar appear temporarily.<br />
    You only see the Bookmarks menu button if the Menu bar is hidden.

  • When I delete a name from the address book it does not delete it from the drop down name menu when forwarding a message. How do I remove it from the drop down menu?

    When I delete a name from Address Book it is not removed from the name drop down list when forwarding a message. How can I remove it from the drop down list?

    In Mail go to the Window Menu and select Previous Recipients. Deleting entries from there won't delete them from your Address Book.

  • In Mail 3.6 how can I delete address from the drop down menu?

    When I update an email address in the Address Book, the drop down menu in a new email is still the old address.

    I think I figured it out. I have to click on the arrow beside the smart address in a new email and delete it there. I tried removing previous recipients but without success. I'm not sure what the name of my software is. Maybe snow leopard. How can I find that?
    Thanks for the suggestion and it probably helped a lot of other users and would have helped me if I knew the software.

  • How do I delete something from the drop-down menu of the URL bar. I went there accidentally and don't want it in the list.

    I directly typed what I thought was the correct URL into the URL box. It took me to a site different from where I was wanting to go. Now that site's URL is in the list of URL's in the drop-down box. Is there some way of deleting this from the drop-down list? It seems to me that there used to be a way to do this--a small x on the right side of each site's URL in the list. After one of the updates this was no longer there.

    touch it with mouse, don't click, and press DELETE.
    tell us if this work for you, thank you

  • Buttons - making a drop down menu

    Hello,
    I only know very basic flash. Right now, I am attempting to revamp a website. The buttons that are currently being used are only gifs that are hyperlinked and there are almost 12 buttons... I think that this is a ridiculous amount of buttons to have. It looks very cluttered.
    So, I figured I should make 6 buttons and just fit the rest of the buttons into subcategorized buttons. And the way to do this is to create flash buttons with drop down menus. To see what I mean, go to this link and look at their buttons:
    http://ca.msn.com/
    Their buttons drop down into menus with sub-categories. I want to do this.
    So far, I have gone into flash, created buttons and made graphics for the "Up" "Over" "Down" and "Hit". I have also added the menu buttons and graphics for the "Over" of each drop-down button-menu.
    I have even provided the action script to link each button to where I need it to go.
    HOWEVER, here is where the problem is. When I roll the mouse over the button, and then move the mouse down to click on one of the buttons in the drop down menu, the menu disappears, OF COURSE, because the mouse goes off the hit. I can't make the hit bigger, because the menu shouldn't open unless it's on the main button. But without the hit being bigger, the menu will always disappear.
    IN ADDITION, I've never used flash buttons on a website before. I'm just using HTML. How do I link the button to the page? Do I save the file as a .swf flash file? And link to 6 different files? Or do I save the buttons in a line, and just use one link?
    I'm on a bit of a deadline so any help is appreciated. Thanks in advance!
    -Michelle

    While I can't help you with your deadline, I can offer a little bit of input.  To take a Flash approach you should find a Flash drop down menu tutorial thru Google and follow thru that to gain an understanding of how to construct one.  The problem you are having with the rollover stems from needing to extend the rollover such that each element of the dropdown also carries that rollover command.  Each button needs to be assigned code to process interacting with it and linking to some other web page.  The swf file that you publish would need to be sized for holding the buttons and then must be placed on the web page.
    The example you pointed to uses a CSS drop down menu, which you will likely find easier to create and manage if you have no familiarity with how to make Flash work in a web site.  I suggest going to the Dreamweaver forum and looking there for information about that approach.

  • Can't get the spinning colorwheel to go away from the drop down menu

    I'm trying to attach a file to an email.  When I click on the attach button and the drop down menu comes down and when I get the cursor over the drop down box the color wheel comes on and won't go off.  I've restarted the computer multiple times and it still happens.  How do I clear this problem?
    quiltingT

    Useful article here on the causes of the Spinning Beach Ball and how to troubleshoot it:
    http://www.computerworld.com/s/article/9177479/Troubleshoot_the_spinning_beach_b all?taxonomyId=89&pageNumber=1
    and also this:
    http://www.thexlab.com/faqs/sbbod.html

  • How do I reset Safari on MacBook Pro, running Yosemite 10.10.3 with Safari V8.0.5? The reset button is not in Preferences, Privacy, nor on the drop-down menu of Safari.

    I have  a 2011 MacBook Pro running Yosemite 10.10.3, and Safari V8.05. I want to reset Safari, but there is no reset in the Safari drop-down nor is there a reset in the Preferences - Privacy window. Any Help out there?

    Hi, thanks for the response.  I have searched online and many posts say to reset Safari all you have to do is click on the Safari icon, then select reset from the drop down menu, or find the reset button in the privacy window in preferences.  My system has neither options. My Safari had been hijacked (frozen) by a pop-up.  I cleared all history, cookies, cache, etc. with the wifi off, and it seems to have worked so far. Many posts said to reset Safari, and I don't seem to have that option.
    Thanks again.

  • How do I turn off the drop-down menu on the back button?

    I use a laptop and my hands aren't too dextrous. Every time I click the "back" button I get the drop down menu, which means I then need to move my hand back to the pad (slowly!) move the pointer, and try again. It can take me several attempts to go back one site now!
    I have searched for hours to find out how to turn this drop down menu off, to no avail, and even looked through all the settings in about:config in an attempt to find a way around this. It seriously impacts my ability to use my laptop on the web now, so if anyone can please come up with a way to get back to the old back button, with no menu when my slow old finger cannot move fast enough to get off the button, I would be very grateful.

    You can use that list and open the previous tab just above the one that appears bold and has a bullet.
    The current active entry has a bullet in front of it.<br />
    If you hover an entry in the tab session history list with the mouse then you see an arrow at the left side pointing left (Back) or right (Forward) to show the direction.<br />
    You can left click an item to open it in the current tab or middle-click or Ctrl left-click an entry in that list to open that link in new tab, just like you can with other links.<br />

  • How do I alphabatize all my bookmarks from the drop down menu with the star on the Right side of screen?

    I want to alphabatize all my bookmarks that are in the drop down menu, the menu with the star icon, on the right side of the screen. I do not want to put them in folders or view them in the box from the menu bar and all the answers pertain to that box, and not to the one with the star. Thank you

    I don't think it's possible from the toolbar button.
    However, the action you take in the Bookmarks Sidebar or in the Library dialog will affect the Bookmarks Menu everywhere it is displayed, including the toolbar button, so you only need to use it for the few moments needed to use Sort By Name and then close it.
    Bookmarks Sidebar (either):
    * View menu > Sidebar > Bookmarks
    * Command+b
    Library dialog (either):
    * Bookmarks menu > Show All Bookmarks
    * Command+Shift+b
    right-click "Bookmarks Menu" > Sort By Name

  • I have a new computer with Windows 7 professional, Office 2007, Adobe XI. I have just created a word document and tried save it as a PDF but the PDF option doesn't appear in the drop down menu. Any ideas please? Thank you.

    I have a new computer with Windows 7 professional, Office 2007, Adobe XI. I have just created a word document and tried save it as a PDF but the PDF option doesn't appear in the drop down menu. Any ideas please? Thank you.

    What is "Adobe XI" - Reader, or Acrobat?
    But either way, 'Save as Adobe PDF' is a Word function, independent of what Adobe software you have installed.

  • Can someone tell me how to create accounting entries with the account status as error

    Hi,
    Can someone tell me how to create accounting entries with the
    account status as error?
    Thanks!!
    Danny

    It's call fixed/static background, and it is NOT directly support by iweb, you will need post processing either in html or javascript.
    Varkgirl (you need to search the previous forum) and I did it since iweb1:
    try Safari, and scroll: http://www.geocities.com/[email protected]/Links.html
    invisible link? roddy, fishing for info again?

  • How do I add more than 10 options to the drop down menu?

    Presently, I'm only able to give ten options but many of my items have 20-30 options.How do I add more than ten options to the drop down menu?

    BrazenChick wrote:
    Presently, I'm only able to give ten options but many of my items have 20-30 options.How do I add more than ten options to the drop down menu?
    It depends on the type of option. If each option has a separate price, then I don't know of a way to add more than 10 options since those options with the prices are encoded into the button id. (Well, you could encode the information yourself with PayPal's API, but that is way more involved than I've been willing to tackle.) If you have more than 10 options such as color, scent, etc that don't affect the price, then you can edit the code you have added to your website to add additional items in the list. For example, suppose you had options "red" and "green", the relevant part of the code would look something like this: <select name="os0">
    <option value="red">red </option>
    <option value="green">green </option></select> If you want to add the option "blue", you would insert the line : <option value="blue">blue </option> before the closing </select> tag. More than 10 options won't be saved in the PayPal button creator, but it will work just fine in your website since this type of option isn't encoded in the id.

  • Bookmarks toolbar changed from the right side of the drop-down menu to the left. How can I change it back on Firefox 4.0.1 for Mac?

    I just updated to Firefox 4.0.1. Some changes I don't like, especially that the Bookmarks toolbar opens to the left of the drop-down menu instead of the right. How can I change it?

    You may have bookmarks that have long title. Firefox 4 shows the full text of the bookmark name, so if it doesn't fit with opening to the right side the Firefox will open to the left side. You can scroll through the list and make the bookmarks with a long name shorter.
    * [[How do I use bookmarks?]]

Maybe you are looking for