JButton and menu

Do you know how I can add popup menu to a mixed jbutton? I need to create a button like JBuilder or eclips run button. I can create simple buttons which will show a popup menu whenever user click it but I had to create a component which contains 2 button one of them will show a popup menu and another will do the next task (exactly like jbuilder run button).
Thanks in advance.

This is a good widget that I found on the web and have been using:// Process Dashboard - Data Automation Tool for high-maturity processes
// Copyright (C) 2003 Software Process Dashboard Initiative
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
// The author(s) may be contacted at:
// Process Dashboard Group
// c/o Ken Raisor
// 6137 Wardleigh Road
// Hill AFB, UT 84056-5843
// E-Mail POC:  [email protected]
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.*;
import javax.swing.border.Border;
public class DropDownButton extends Box {
    private JButton mainButton;
    private JButton dropDownButton;
    private boolean dropDownEnabled = false;
    private boolean mainRunsDefaultMenuOption = true;
    private Icon enabledDownArrow, disDownArrow;
    private DropDownMenu menu;
    private MainButtonListener mainButtonListener = new MainButtonListener();
    public DropDownButton(JButton mainButton) {
        super(BoxLayout.X_AXIS);
        menu = new DropDownMenu();
        menu.getPopupMenu().addContainerListener(new MenuContainerListener());
        JMenuBar bar = new JMenuBar();
        bar.add(menu);
        bar.setMaximumSize(new Dimension(0,100));
        bar.setMinimumSize(new Dimension(0,1));
        bar.setPreferredSize(new Dimension(0,1));
        add(bar);
        this.mainButton = mainButton;
        mainButton.addActionListener(mainButtonListener);
        mainButton.setBorder
            (new RightChoppedBorder(mainButton.getBorder(), 2));
        add(mainButton);
        enabledDownArrow = new SmallDownArrow();
        disDownArrow = new SmallDisabledDownArrow();
        dropDownButton = new JButton(disDownArrow);
        dropDownButton.setDisabledIcon(disDownArrow);
        dropDownButton.addMouseListener(new DropDownListener());
        dropDownButton.setMaximumSize(new Dimension(11,100));
        dropDownButton.setMinimumSize(new Dimension(11,10));
        dropDownButton.setPreferredSize(new Dimension(11,10));
        dropDownButton.setFocusPainted(false);
        add(dropDownButton);
        setEnabled(false);
    public DropDownButton()                 { this(new JButton());     }
    public DropDownButton(Action a)         { this(new JButton(a));    }
    public DropDownButton(Icon icon)        { this(new JButton(icon)); }
    public DropDownButton(String text)      { this(new JButton(text)); }
    public DropDownButton(String t, Icon i) { this(new JButton(t, i)); }
    public JButton getButton()         { return mainButton;     }
    //public JButton getDropDownButton() { return dropDownButton; }
    public JMenu   getMenu()           { return menu;           }
    public void setEnabled(boolean enable) {
        mainButton.setEnabled(enable);
        dropDownButton.setEnabled(enable);
    public boolean isEnabled() {
        return mainButton.isEnabled();
    public boolean isEmpty() {
        return (menu.getItemCount() == 0);
    /** Set the behavior of the main button.
     * @param enable if true, a click on the main button will trigger
     *    an actionPerformed() on the first item in the popup menu.
    public void setRunFirstMenuOption(boolean enable) {
        mainButton.removeActionListener(mainButtonListener);
        mainRunsDefaultMenuOption = enable;
        setEnabled(mainRunsDefaultMenuOption == false ||
                   isEmpty() == false);
        if (mainRunsDefaultMenuOption)
            mainButton.addActionListener(mainButtonListener);
    /** @return true if a click on the main button will trigger an
     *    actionPerformed() on the first item in the popup menu.
    public boolean getRunFirstMenuOption() {
        return mainRunsDefaultMenuOption;
    private void setDropDownEnabled(boolean enable) {
        dropDownEnabled = enable;
        dropDownButton.setIcon(enable ? enabledDownArrow : disDownArrow);
        if (mainRunsDefaultMenuOption)
            setEnabled(enable);
    /** This object responds to events on the main button. */
    private class MainButtonListener implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            if (mainRunsDefaultMenuOption && !isEmpty()) {
                JMenuItem defaultItem = menu.getItem(0);
                if (defaultItem != null)
                    defaultItem.doClick(0);
    /** This object responds to events on the drop-down button. */
    private class DropDownListener extends MouseAdapter {
        boolean pressHidPopup = false;
        public void mouseClicked(MouseEvent e) {
            if (dropDownEnabled && !pressHidPopup) menu.doClick(0);
        public void mousePressed(MouseEvent e) {
            if (dropDownEnabled) menu.dispatchMouseEvent(e);
            if (menu.isPopupMenuVisible())
                pressHidPopup = false;
            else
                pressHidPopup = true;
        public void mouseReleased(MouseEvent e) { }
    /** This object watches for insertion/deletion of menu items in
     * the popup menu, and disables the drop-down button when the
     * popup menu becomes empty. */
    private class MenuContainerListener implements ContainerListener {
        public void componentAdded(ContainerEvent e) {
            setDropDownEnabled(true);
        public void componentRemoved(ContainerEvent e) {
            setDropDownEnabled(!isEmpty());
    /** An adapter that wraps a border object, and chops some number of
     *  pixels off the right hand side of the border.
    private class RightChoppedBorder implements Border {
        private Border b;
        private int w;
        public RightChoppedBorder(Border b, int width) {
            this.b = b;
            this.w = width;
        public void paintBorder(Component c,
                                Graphics g,
                                int x,
                                int y,
                                int width,
                                int height) {
            Shape clipping = g.getClip();
            g.setClip(x, y, width, height);
            b.paintBorder(c, g, x, y, width + w, height);
            g.setClip(clipping);
        public Insets getBorderInsets(Component c) {
            Insets i = b.getBorderInsets(c);
            return new Insets(i.top, i.left, i.bottom, i.right-w);
        public boolean isBorderOpaque() {
            return b.isBorderOpaque();
    private class DropDownMenu extends JMenu {
        public void dispatchMouseEvent(MouseEvent e) {
            processMouseEvent(e);
    /** An icon to draw a small downward-pointing arrow.
    private static class SmallDownArrow implements Icon {
        Color arrowColor = Color.black;
        public void paintIcon(Component c, Graphics g, int x, int y) {
            g.setColor(arrowColor);
            g.drawLine(x, y, x+4, y);
            g.drawLine(x+1, y+1, x+3, y+1);
            g.drawLine(x+2, y+2, x+2, y+2);
        public int getIconWidth() {
            return 6;
        public int getIconHeight() {
            return 4;
    /** An icon to draw a disabled small downward-pointing arrow.
    private static class SmallDisabledDownArrow extends SmallDownArrow {
        public SmallDisabledDownArrow() {
            arrowColor = new Color(140, 140, 140);
        public void paintIcon(Component c, Graphics g, int x, int y) {
            super.paintIcon(c, g, x, y);
            g.setColor(Color.white);
            g.drawLine(x+3, y+2, x+4, y+1);
            g.drawLine(x+3, y+3, x+5, y+1);
}Test Code Snippet:        JButton button = new JButton("Action");
     DropDownButton b = new DropDownButton(button);
     b.setEnabled(true);
     JMenu m = b.getMenu();
     m.add(new JMenuItem("Item 1")) ;
     m.add(new JMenuItem("Item 2")) ;
        toolbar.add(b);Voila!

Similar Messages

  • Forms 6.0 and menu

    I've converted forms and menu from 4.5 to 6.0, got all regestry settings in place for forms6.0, and when I run the form I get
    an error "FRM-10256 User is not authorized
    to run Form Builder Menu" - form comes up fine but the menu does not, even though
    everything works in 4.5.
    Has anyone seen that error?
    thanks in advance.
    null

    It has been a while since I fixed this problem, but I think you have to run FRM50SEC.sql and then grant select on the FRM50_ENABLED_ROLES view to your target audience.
    Try This...
    create or replace view FRM50_ENABLED_ROLES as
    select urp.granted_role role,
    sum(distinct decode(rrp.granted_role,
    'ORAFORMS$OSC',2,
    'ORAFORMS$BGM',4,
    'ORAFORMS$DBG',1,0)) flag
    from sys.user_role_privs urp, role_role_privs rrp
    where urp.granted_role = rrp.role (+)
    and urp.granted_role not like 'ORAFORMS$%'
    group by urp.granted_role;
    create public synonym FRM50_ENABLED_ROLES for system.FRM50_ENABLED_ROLES;
    create role ORAFORMS$OSC;
    create role ORAFORMS$DBG;
    create role ORAFORMS$BGM;
    -- Added
    grant select on frm50_enabled_roles to public;
    null

  • Hi, I was using my iPod Touch and then all of a sudden, the screen went black. So I held the the on and menu button to reboot it and so it shut of and came back on and been on the loading screen for an hour. What can I do to fix it?

    Hi, I was using my iPod Touch and then all of a sudden, the screen went black. So I held the on/off button and menu button to reboot it. So it turned off then back on but it has been stuck on the loading page for an hour. What's wrong with it?

    - Let the battery fully drain. After charging for at least an hour try here:
    iOS: Not responding or does not turn on

  • Is the high definition (HD) display of my new laptop the culprit behind my tiny impossible to read icons and menu headers in all my CS5 adobe programs?

    The toolbox icons and menu headers are too small to read in all my adobe cs5 programs. I just purchased a new laptop with a high definition (HD) screen and 1920x1080 resolution. So far I tried dropping the resolution to 1680x1050 that does not solve the problem. I went into photoshop preferences/interface and bumped up text size to "large" and that made text in menus readable but not the icons or menu headers. Then it occurred to me, the one thing that is different is the HD display. Does anyone know if that is the reason for the tiny icons and text?  Thanks for your help.

    Hi Gene,
    I tried what you mentioned and wow! the icons and menu headers in photoshop are a normal size again.
    One other thing I did since my first post, I found a way to bump up the size of text in the display settings of Windows and that fixed readability in most of the adobe products I use ( acrobat pro, illustrator, indesign, bridge-somewhat) but not photoshop. Anyways, thanks for your advice! you have saved me from ruining my eyesight.
    - Carmen

  • Dock and Menu disappear only for Safari

    My dock and menu disappear only when I am using Safari. They re-appear when I hover my mouse at the location that they should be at, but for some reason their default positions are to be hidden.
    The dock and menu are present for all other apps and when I'm on the desktop--basically whenever Safari isn't "chosen" as the active window.
    I have checked to make sure that Safari is NOT in Full Screen mode. What could be the problem?

    This has happened to me before and it took me a long time to work it out.
    But all you need to do is froce quit safari or any application that this is happening to and start the application again.
    Hope it works.
    SGosai

  • How to deploy Forms, Reports and Menu from Client to Server machine

    Dear Experts,
    I have one requirement to deploy the Forms, Reports and Menu from client machine to server machine.
    Deployment involves the following steps :
    1. Firstly we have to search the selected file in a folder where the .fmx is present ( in Server machine) and take the back up of the the existing file in the server (Source and destination paths will be available).
         Ex. If the existing FMB name is TEST.fmx then the backup file should be TEST_sysdate.fmx.
    2. Secondly we have to transfer the file from the client folder (or from another folder of the same server) to the server folder where the back up exists.
    Please help me to search/rename/copy/replace the _.fmx/.rdf/.rep/.mmx_ files from client to server.
    We are using
    9i Database.
    10g Forms and reports.
    SQL Developer tool.
    OS is Windows (Client and Server).
    Help me out to attach a file of front end screen which we are planning to develop. It will give a clear picture on this requirement.
    Thanks :)
    Edited by: 941175 on Jun 17, 2012 9:09 AM
    Edited by: 941175 on Jun 17, 2012 9:12 AM
    Edited by: 941175 on Jun 17, 2012 9:14 AM

    941175
    Welcome to the forum. Please take a while to go through the FAQ to be found to the top right of the page.
    Your issue is more to do with batch files rather than Forms. The only relation with Forms, as I see it, is that you will be using HOST/CLIENT_HOST to start a batch file with the file name to be deployed as a parameter passed to it.
    You need to rewrite either a CMD batch file or a Powershell script to achieve what have set out to do.
    For CMD batch files look up http://www.robvanderwoude.com/battech.php , or any of the other excellent resources available on the internet.
    Regards,

  • HT201274 what should i do if i interrupted the erase all content process from my ipod i pressed sleep button and menu button for 10 seconds

    please help here i just interrupted the process of erasing all content from my ipod it took almost 10 hours then i got worried from waiting i pressed both sleep button and menu button for 10 seconds while in process what should i do?

    After charging the iPod for at least an hour try:
    - Reset iPod touch: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Connect to computer and restore via iTunes
    - Next see if placing the iPod in Recovery mode will allow a restore.
    - Then try DFU mode and a restore.
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings

  • Screen Painter and Menu Painter Translations

    Hello All,
    I want to translate the Screen painter and Menu Painter Objects .
    When I go to the SE41 and select the PF Status of my Program and press change Button I'm getting the following msg :
    Make repairs in foreign namespaces only if they are urgent .
    If I press Ok and select the Menu path : Goto --> Translation .
    The Translation options is in deactivated mode.
    How to do the Translation now ?
    Regards,
    Deepu.K

    Hi
    Run trx SE63, then go to: Translation->Short Texts->Screen Painter
    Choose:
    - Header to translate the title of attribute of the screen;
    - Texts   to translate the label of the input/ouput fields
    Translation->Short Texts->User interface to translate the menu
    Max

  • ActionListener with JButton and JMenu

    How do I implement actions for both a JButton and a JMenuItem? Would I have to set it in the actionPerformed method(Action e), because that doesn't seem to work, or else I don't know how to do it. Help would be appreciated.

    But the thing is that I don't want the same action for both the Button and MenuItem.Then create separate ActionListeners for each component.
    button.add(new ActionListener()
        public void actionPerformed(ActionEvent e)
            // add your code here
    }Or test which button was pressed in the actionPerformed method. The Swing tutorial on How to Use Buttons, gives example of this:
    http://java.sun.com/docs/books/tutorial/uiswing/components/button.html

  • 5.1.3 Restoring bookmarks bar and menu ?

    I'm running Safari 5.1.3 on imac on 10.7.3
    I just synced my ipad to computer.
    On my bookmarks bar on the ipad I had only 2 bookmarks. On the computer I had a whole bunch. Same with bookmarks menu.
    After the sync, on my computer, it had deleted all the bookmarks on my bookmarks bar, and only left me the 2 that were on the ipad. Same with bookmarks menu.
    Seems to have affected bookmarks bar and menu only. Rest of bookmarks are OK.
    I have an external backup drive and backed up a week ago. But, have never had to restore anything.
    What's the procedure to restore the bookmarks bar and menu in Safari, using time machine?
    Thanks.

    The only way is to restore from a useful backup, if you have one.
    If you sync the iPad to iTunes and use Time Machine regularly, you would likely have the appropriate backup to restore from. In that case:
    Restore the iPad backup set from Time Machine from a date before you overwrote the bookmarks. The location of the backup is ~/Library/Application Support/MobileSync/Backup/ (you can get to it by pressing Cmd+Shift+G in the Finder and entering this path).
    Connect the iPad, run iTunes and restore from the backup.
    If you use iCloud Backup, then you can restore from iCloud and choose which date's backup you'd like to restore from. You can check if you're using iCloud Backup by opening the Settings app on the iPad, then going to the iCloud submenu and looking at the status right below "Storage & Backup", where it would say "iCloud Backup is off." (or "iCloud Backup is on.", as the case may be).
    In any case, keep in mind that restoring from a backup means you lose all application data changes after the date of the backup.
    Also see Restoring from a previous iCloud backup.

  • Right part of menu bar and menu bar clock freezes.

    Right part of menu bar and menu bar clock freezes after a few minutes works. Happens every single session and seems to not be affected of what programs that are running.  There are other anomalities too, which seem to be somehow related, affecting my main software (Finale).  Keyboard Maestro and Time Machine are always running in the background.  Any ideas?

    Nope.
    BTW:  After restart, it all seems to work.  This seems to happen after the MBP has been taking a nap and in all following sessions.
    It's a 2 months old MBP, 8 gB RAM, all the newest updates on everything.

  • Repetition in Bookmarks Bar and Menu Sidebar, shifting in MenuBar,

    I am seeing deleted bookmarks return as well as it seems a neverending growth and repetetion of my bookmarks since 5.1.2 update and numerous repeats in the bookmarks bar and menu. See attached screenshot. Yes, I used MobileMe and have been using iCloud since so I suspect it is related.
    Thanks for any thoughts

    Actually, it just keeps growing. Even more repetition today. I have emptied cache, reset Safari, replaced the bookmark.plist file with an older Time Machine backup and within minures it starts repopulating and starts all over again growing in duplications. This has to be iCloud related in my opinion. If not, where is it coming from.
    It seems various threads with different descriptions of the same problem or a variant of bookmarks and menubar issue are being addressed in this Safari forum, and most just started seeing this it seems in the last several weeks but not before the 5.1.2 update.
    Does anyone else think so? This appears to need Apple Support attention at an advanced level, as all the suggestions, while great to have and try, they are not working. I'll bet this issue is very widespread, just not observed or reported yet.

  • Using a Button Bar and Menu Control

    Hi All,
    I am using button bar and menu bar control .But the problem  i am facing is that  how to align menu to the bottom of respective button of button bar.
    Tanks In advance

    Hi All,
    I am using button bar and menu bar control .But the problem  i am facing is that  how to align menu to the bottom of respective button of button bar.
    Tanks In advance

  • Bookmark bar and menu stop working after awhile on Firefox 12

    I have upgraded to Firefox 12. Everything works fine when I start up Firefox, but after some amount of use (and I can't always reproduce this) eventually when I click on bookmarks in my Bookmark Bar or from the Bookmark menu, nothing happens. Firefox doesn't load the bookmark. If I open the "Show All Bookmarks" window and click on bookmarks there, they load fine and then the menu and bookmark bar suddenly start working again. If I close the "Show All Bookmarks" window the Bookmark Bar and menu stop working again.

    Hi ischou,
    I haven't heard of this particular issue, but you might want to try starting Firefox in [[Safe Mode]]. Let is sit for a while as you described above and if you don't have the issue while all of your add-ons, extensions, and themes are disabled, you can try adding them back in one by one until you find the culprit. You should look at the [https://support.mozilla.org/en-US/kb/Troubleshooting-extensions-themes Extensions and Themes troubleshooting guide ] and the [[Troubleshooting plugins]] article as well.
    You could also try [https://support.mozilla.org/en-US/kb/Managing-profiles?s=create+a+new+profile&r=2&e=es&as=s#w_creating-a-profile Creating a new profile].
    Hopefully this helps!

  • Leaving title bar and menu

    Hi there,
    I have a problem with acrobat reader since XI 11.xx.... If i manipulate acrobat's window (full screen, sized etc). I have all the time je same result, title bar and menu bar are not displayed correctly.
    Someone already have this graphical glich ?
    I must click on another application to get a correct window...
    So what can i do for this ?!
    Also, CustWiz for acrobat reader will be proposed when ?!
    Thanks

    Do you have Kaspersky software installed?  If so, update to the latest version.

Maybe you are looking for

  • Help with multiple users in iTunes

    Dear all I seem to have made a right mess of iTunes. It all started with my 80gb Classic ipod and iTunes on my Toshiba Windows 8 laptop. All was fine then my daughter got an iPod touch and I think here was where I made my first mistake. I setup a new

  • Anyone having an issue with the SD TV show option not working in iTunes Store?

    SD TV shows are not available to purchase, I can only get the HD shows.  Is anyone else having this problem?

  • Video Quality and Photo Quality HORRIBLE

    I've looked all over the forums here and the only problem people seem to consistently harp on is the sluggishness/bugginess of the App. OK. I agree... BUT... HAS ANYONE NOTICED THE QUALITY OF YOUR iMovie's IS NOW WORSE THAN 5?! This is ridiculous! I

  • OAF Personalization : print output of a query on a OAF page

    I have a requirement in OAF form. Wanted to check if it is possible I needed to print a value on the form which would be a query output. Basically in my requisiiton workflow i have changed teh approver. Based on that the OAF page doesnt reflect the c

  • UCCX 9 web services / Stored Procedure

    I'll appreciate if you guys can help me on this...   Our application group already created automated bill payment web site.  I would like to do similar things by using UCCX 9.  When customers call, they enter Customer ID, credit card/check number and