Button like JToolBar-button in JMenuBar

I want to have a button with a functionality like a JToolBar-button in a JMenuBar with the LookAndFeel of the JMenuBar.
A normal JButton can be integrated, but the LookAndFeel does not fit.
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;
public class JMenuBarBeispiel implements ActionListener {
     JFrame applikation;
     Container container;
     // Menüleiste
     JMenuBar menueLeiste;
     // Menüleiste Elemente
     JMenu datei;
     JMenu hilfe;
     // Datei
     JMenuItem oeffnen;
     JMenuItem beenden;
     // Hilfe
     JMenuItem faq;
     JMenuItem about;
     // Textfeld
     JTextArea textarea;
     public JMenuBarBeispiel() {
          applikation = new JFrame("JMenuBar Beispiel");
          container = applikation.getContentPane();
          // Menüleiste erzeugen
          menueLeiste = new JMenuBar();
          // Menüelemente erzeugen
          datei = new JMenu("Datei");
          hilfe = new JMenu("Hilfe");
          // Untermenüelemente erzeugen
          oeffnen = new JMenuItem("öffnen");
          oeffnen.addActionListener(this);
          beenden = new JMenuItem("beenden");
          beenden.addActionListener(this);
          faq = new JMenuItem("F.A.Q.");
          faq.addActionListener(this);
          about = new JMenuItem("Über");
          about.addActionListener(this);
          // Menüelemente hinzufügen
          menueLeiste.add(datei);
          menueLeiste.add(hilfe);
          JButton jButton=new JButton("test");
          menueLeiste.add(jButton);
          // Untermenüelemente hinzufügen
          datei.add(oeffnen);
          datei.add(beenden);
          hilfe.add(faq);
          hilfe.add(about);
          // Textfeld erzeugen
          textarea = new JTextArea();         
          applikation.add(menueLeiste, BorderLayout.NORTH);
          applikation.add(new JScrollPane(textarea), BorderLayout.CENTER);
          applikation.setSize(400, 300);
          applikation.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//               try{
//                    javax.swing.UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
//                    javax.swing.SwingUtilities.updateComponentTreeUI(applikation);
//               }catch(Exception e){}
          applikation.setVisible(true);
     public void actionPerformed(ActionEvent object) {
          if (object.getSource() == oeffnen){
               System.out.println("öffnen wurde angeklickt");
          if (object.getSource() == beenden){
               System.out.println("beenden wurde angeklickt");
          if (object.getSource() == faq){
               System.out.println("faq wurde angeklickt");
          if (object.getSource() == about){
               System.out.println("über wurde angeklickt");
     public static void main(String[] args) {
          new JMenuBarBeispiel();
}

Please don't make duplicate posts. You already posted this same question yesterday, in this very forum:
[http://forums.sun.com/thread.jspa?threadID=5434234&messageID=10963870#10963870]
Did you try my suggestion I made in that thread? If so, and assuming it didn't work, what else did you try?

Similar Messages

  • Keep dialog on top while clicking elsewhere, like JToolBar

    Hi,
    I have a JDialog, that once it is open I would like for it to remain visible even if the user clicks elsewhere in the application. If the user clicks in the application the dialog should just lose focus (but not get hidden)...the JToolBar has this functionality. When u "undock" a JToolBar the dialog (or frame, not sure what it is) does not get hidden when something else gets focus...how/what can i do to solve my problem?
    thanks

    for anyone who cares...u need a window ancestor for ur dialog..u can find it by this
         JDialog dialog;
         Window window = SwingUtilities.getWindowAncestor(toolbar);
         if (window instanceof Frame) {
         dialog = new ToolBarDialog((Frame)window, toolbar.getName(), false);
         } else if (window instanceof Dialog) {
         dialog = new ToolBarDialog((Dialog)window, toolbar.getName(), false);
         } else {
         dialog = new ToolBarDialog((Frame)null, toolbar.getName(), false);
         }

  • No buttons showing

    Hello everyone, im new to java and I would be greaful for your help:
    My problem is this: my swing app doesn't show the JMenuBar, can any one point me in the direction in where im going wrong?
    import java.awt.*;
    import java.awt.Event.*;
    import javax.swing.*;
    import javax.xml.transform.Source;
    public class main extends simpleFrame{
         private shape squareShape;
         private frame aFrame;
          * Menu buttons
         public JMenuBar menuBar = new JMenuBar();
         public JMenu file = new JMenu("File");
         public JMenuItem start = new JMenuItem("Start");
         public static void main(String[] args)
              main game1 = new main();
              game1.showIt("Title");
         public void gridLayout()
              Source[][] mySpace = new Source[20][20];
         public void main()
              squareShape = new shape(); // makes a new sqaure
              this.setJMenuBar(menuBar);
              menuBar.add(file);
              file.add(start);
              this.getContentPane().add(aFrame);
              pack();
         public void score()
              //to do
    }Thank you

    can any one point me in the direction in where im going wrong?Well your code isn't complete, so I'm not going to spend time guessing what the rest of it looks like. For example:
    a) you reference a method showIt(), but its not included
    b) you included a method main() where you attempt to add the menu to the frame, but you never invoke that method from anywhere.
    Also, learn the Java coding conventions. For example class names are upper cased. (ie. main should be Main, simpleFrame should be SimpleFrame)
    The best I can do is point you to the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/menu.html]How to Use Menus which has working examples.
    I suggest you download the entire tutorial from here:
    http://java.sun.com/docs/books/tutorial/

  • Newbie help: Layout Managers

    Hi,
    as a newbie in Swing I have difficulties with the Layout Managers... I have read the Swing tutorial but it's still a little bit complicated:
    I have a JPanel, I would like to add a JMenuBar, a JToolbar and then 2 additional JPanels at the top and on the left representing rulers like in the "How a Scroll Pane Works" example at
    http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html as well as a JTable on the right.
    How can I do this... BorderLayout containing my main JPanel at CENTER and the two JPanels representing the rulers at PAGE_START and LINE_START and the JTable at LINE_END? Where can I place then my menu- and toolbar? Can I add a BoxLayout to PAGE_START for that?
    In a posting here at the forum I read that the MenuBar should be added to the root Pane. How do I do this? When do I use Content Pane, Layered Pane and Glass Pane?
    Do you know a simple example or good tutorials at the web?
    Thanks a lot!

    Thank you for the link about the rulers.
    The rulers goes inside your custom component. It will be like the example at http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html
    Other stuffs layered like this.
    package tmp;
    import javax.swing.*;
    import java.awt.*;
    public class LayoutExample extends JFrame
        public static void main( String[] args ) throws Exception
            SwingUtilities.invokeAndWait( new Runnable()
                public void run()
                    // All the interaction with GUI do inside the MessageLoop thread!
                    LayoutExample l = new LayoutExample();
                    l.pack();
                    l.setVisible( true );
        protected JMenuBar mainMenu;
        protected JToolBar mainToolBar;
        protected RulesFeaturedScrolPane scrollPane;
        public LayoutExample() throws HeadlessException
            super();
            setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
            setTitle( "Layout Example" );
            // -------------- CREATING NECESSARY CONTROLS ----------------
            // Menu
            mainMenu = new JMenuBar();
            JMenu mnuFile = mainMenu.add( new JMenu( "File" ) );
            mnuFile.add( new JMenuItem( "Open" ) );
            // ToolBar
            mainToolBar = new JToolBar();
            mainToolBar.add( new JButton( "Open" ) );
            // Customized JScrollPane (with rulers)
            scrollPane = new RulesFeaturedScrolPane();
            // -------------- END OF CREATING NECESSARY CONTROLS ----------------
            // Settig up the components
            setJMenuBar( mainMenu ); // Menu added to JFrame not to its ContentPane
            getContentPane().setLayout( new BorderLayout() );
            getContentPane().add( mainToolBar, BorderLayout.NORTH ); // ToolBar added to the ContentPane
            getContentPane().add( scrollPane, BorderLayout.CENTER ); // Other components added to ContentPane
        public static class RulesFeaturedScrolPane extends JPanel // <----------- this may extend JScrollPane
            public RulesFeaturedScrolPane()
                add( new JLabel( "TODO: this class should have rulers" ) );
    }Most interesting things starts at getContentPane().setLayout( new BorderLayout() );

  • Adding menu-like buttons to JToolBar (such as Back button in Netscape)

    Hi,
    I wonder wether it is possible to add a menu-like button to a JToolBar. I tried adding a JMenu but didn't succed, since the menu's visual appearance was completely messed up and, furthermore, it didn't respond to mouse clicks.
    Any hints appreciated.
    Janek.

    To do that, I wrote 3 classes.
    At the end, the new menu reacts and can be used exactly as a JMenu.
    The first class is the menu class which extends JMenu :
    import javax.swing.*;
    * This class override the method boolean isTopLevelMenu() to
    * allow a menu to be a top level menu in a JMenuBar and a JTollBar also !
    public class MyMenu extends JMenu {
        public MyMenu() {
            super("");
        public MyMenu(String s) {
              super(s);
        public MyMenu(Action a) {
              super(a);
        public MyMenu(String s, boolean b) {
            super(s,b);
         * Returns true if the menu is a 'top-level menu', that is, if it is
         * the direct child of a menubar.
         * @return true if the menu is activated from the menu bar;
         *         false if the menu is activated from a menu item
         *         on another menu
        public boolean isTopLevelMenu() {
            if (getParent() instanceof JMenuBar  || (getParent() instanceof JToolBar))
                return true;       
            return false;
    }The second class extends JToolBar. It is necessary to redefine the MenuBar behavior : When a menu is pressed, you can move the mouse over the other menus and they will open themselves, etc... So the toolbar must implements the interface MenuElement
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    import java.util.*;
    * This class implements MenuElement to obtain the same behavior
    * as a JMenuBar.
    public class MyToolBar extends JToolBar implements MenuElement {
         public MyToolBar() {
              super();
         * Implemented to be a <code>MenuElement</code> -- does nothing.
         * @see #getSubElements
        public void processMouseEvent(MouseEvent event,MenuElement path[],MenuSelectionManager manager) {
         * Implemented to be a <code>MenuElement</code> -- does nothing.
         * @see #getSubElements
        public void processKeyEvent(KeyEvent e,MenuElement path[],MenuSelectionManager manager) {
         * Implemented to be a <code>MenuElemen<code>t -- does nothing.
         * @see #getSubElements
        public void menuSelectionChanged(boolean isIncluded) {
         * Implemented to be a <code>MenuElement</code> -- returns the
         * menus in this tool bar.
         * This is the reason for implementing the <code>MenuElement</code>
         * interface -- so that the menu bar can be treated the same as
         * other menu elements.
         * @return an array of menu items in the menu bar.
        public MenuElement[] getSubElements() {
            MenuElement result[];
            Vector tmp = new Vector();
            int c = getComponentCount();
            int i;
            Component m;
            for(i=0 ; i < c ; i++) {
                m = getComponent(i);
                if(m instanceof MenuElement)
                    tmp.addElement(m);
            result = new MenuElement[tmp.size()];
            for(i=0,c=tmp.size() ; i < c ; i++)
                result[i] = (MenuElement) tmp.elementAt(i);
            return result;
         * Implemented to be a <code>MenuElement</code>. Returns this object.
         * @return the current <code>Component</code> (this)
         * @see #getSubElements
        public Component getComponent() {
            return this;
    }The last class and morer difficult is the MenuUI. In my implementation, I use the WindowsLookAndFeel, so I redefine the WindowsMenuUI to look like Windows.
    I give you my code also (please, imagine how difficult it was to write!) :
    import com.sun.java.swing.plaf.windows.*;
    import java.awt.*;
    import java.awt.event.MouseEvent;
    import javax.swing.plaf.ComponentUI;
    import javax.swing.plaf.basic.BasicMenuUI;
    import javax.swing.plaf.basic.BasicGraphicsUtils;
    import javax.swing.event.MouseInputListener;
    import javax.swing.*;
    * Windows rendition of the component.
    * <p>
    * <strong>Warning:</strong>
    * Serialized objects of this class will not be compatible with
    * future Swing releases.  The current serialization support is appropriate
    * for short term storage or RMI between applications running the same
    * version of Swing.  A future release of Swing will provide support for
    * long term persistence.
    public class MyWindowsMenuUI extends WindowsMenuUI {
        private boolean isMouseOver = false;
         private int shiftOffset = 0;
         private int defaultTextShiftOffset = 1;
        public static ComponentUI createUI(JComponent x) {
              return new MyWindowsMenuUI();
         * Draws the background of the menu.
         * @since 1.4
        protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor) {
              ButtonModel model = menuItem.getModel();
              Color oldColor = g.getColor();
            int menuWidth = menuItem.getWidth();
            int menuHeight = menuItem.getHeight();
              UIDefaults table = UIManager.getLookAndFeelDefaults();
              Color highlight = table.getColor("controlLtHighlight");
              Color shadow = table.getColor("controlShadow");
              g.setColor(menuItem.getBackground());
              g.fillRect(0,0, menuWidth, menuHeight);
              clearTextShiftOffset();
            if(menuItem.isOpaque()) {
                if (model.isArmed()|| (menuItem instanceof JMenu && model.isSelected())) {
                        // Draw a lowered bevel border
                        g.setColor(shadow);
                        g.drawLine(0,0, menuWidth - 1,0);
                        g.drawLine(0,0, 0,menuHeight - 2);
                        g.setColor(highlight);
                        g.drawLine(menuWidth - 1,0, menuWidth - 1,menuHeight - 2);
                        g.drawLine(0,menuHeight - 2, menuWidth - 1,menuHeight - 2);
                        setTextShiftOffset();
                   else
                   if (isMouseOver() && model.isEnabled()) {
                        // Draw a raised bevel border
                        g.setColor(highlight);
                        g.drawLine(0,0, menuWidth - 1,0);
                        g.drawLine(0,0, 0,menuHeight - 2);
                        g.setColor(shadow);
                        g.drawLine(menuWidth - 1,0, menuWidth - 1,menuHeight - 2);
                        g.drawLine(0,menuHeight - 2, menuWidth - 1,menuHeight - 2);
                   else {
                        g.setColor(menuItem.getBackground());
                        g.fillRect(0,0, menuWidth, menuHeight);
              g.setColor(oldColor);
         * Method which renders the text of the current menu item.
         * <p>
         * @param g Graphics context
         * @param menuItem Current menu item to render
         * @param textRect Bounding rectangle to render the text.
         * @param text String to render
         * @since 1.4
        protected void paintText(Graphics g, JMenuItem menuItem, Rectangle textRect, String text) {
              ButtonModel model = menuItem.getModel();
              FontMetrics fm = g.getFontMetrics();
              int mnemonicIndex = menuItem.getDisplayedMnemonicIndex();
              // W2K Feature: Check to see if the Underscore should be rendered.
              if (WindowsLookAndFeel.isMnemonicHidden()) {
                   mnemonicIndex = -1;
              Color oldColor = g.getColor();
              if(!model.isEnabled()) {
                   // *** paint the text disabled
                   if ( UIManager.get("MenuItem.disabledForeground") instanceof Color ) {
                        g.setColor( UIManager.getColor("MenuItem.disabledForeground") );
                        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex, textRect.x, textRect.y + fm.getAscent());
                   else {
                        g.setColor(menuItem.getBackground().brighter());
                        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex, textRect.x, textRect.y + fm.getAscent());
                        g.setColor(menuItem.getBackground().darker());
                        BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex, textRect.x - 1, textRect.y + fm.getAscent() - 1);
              else {
                   // For Win95, the selected text color is the selection forground color
                   if (WindowsLookAndFeel.isClassicWindows() && model.isSelected()) {
                        g.setColor(selectionForeground); // Uses protected field.
                   BasicGraphicsUtils.drawStringUnderlineCharAt(g,text, mnemonicIndex,  textRect.x+getTextShiftOffset(), textRect.y + fm.getAscent()+getTextShiftOffset());
              g.setColor(oldColor);
         * Set the temporary flag to indicate if the mouse has entered the menu.
        private void setMouseOver(boolean over) {
              isMouseOver = over;
         * Get the temporary flag to indicate if the mouse has entered the menu.
        private boolean isMouseOver() {
              return isMouseOver;
        protected MouseInputListener createMouseInputListener(JComponent c) {
            return new WindowsMouseInputHandler();
        protected void clearTextShiftOffset(){
            shiftOffset = 0;
        protected void setTextShiftOffset(){
            shiftOffset = defaultTextShiftOffset;
        protected int getTextShiftOffset() {
            return shiftOffset;
         * This class implements a mouse handler that sets the rollover flag to
         * true when the mouse enters the menu and false when it exits.
         * @since 1.4
        protected class WindowsMouseInputHandler extends BasicMenuUI.MouseInputHandler {
              public void mousePressed(MouseEvent e) {
                   JMenu menu = (JMenu)menuItem;
                   if (!menu.isEnabled())
                        return;
                   MenuSelectionManager manager = MenuSelectionManager.defaultManager();
                   if (menu.isTopLevelMenu()) {
                        if (menu.isSelected()) {
                             manager.clearSelectedPath();
                        else {
                             Container cnt = menu.getParent();
                             if(cnt != null && (cnt instanceof JMenuBar || (cnt instanceof JToolBar))) {
                                  MenuElement me[] = new MenuElement[2];
                                  me[0]=(MenuElement)cnt;
                                  me[1]=menu;
                                  manager.setSelectedPath(me);
                MenuElement selectedPath[] = manager.getSelectedPath();
                if (!(selectedPath.length > 0 && selectedPath[selectedPath.length-1] == menu.getPopupMenu())) {
                        if (menu.isTopLevelMenu() || menu.getDelay() == 0) {
                             MenuElement newPath[] = new MenuElement[selectedPath.length+1];
                             System.arraycopy(selectedPath,0,newPath,0,selectedPath.length);
                             newPath[selectedPath.length] = menu.getPopupMenu();
                             manager.setSelectedPath(newPath);
                        else {
                            setupPostTimer(menu);
              public void mouseEntered(MouseEvent evt) {
                   super.mouseEntered(evt);
                   if (!WindowsLookAndFeel.isClassicWindows()) {
                        setMouseOver(true);
                        menuItem.repaint();
              public void mouseExited(MouseEvent evt) {
                   super.mouseExited(evt);
                   if (!WindowsLookAndFeel.isClassicWindows()) {
                        setMouseOver(false);
                        menuItem.repaint();
    }This UI simulate also the rollover effect.
    And now here is a class to test this code (under 1.4 and Windows L&F):
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.plaf.basic.*;
    public class MenuToolBar extends JFrame {
         public static String windowsUI = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
         public MenuToolBar() {
              super("Menu toolbar");
              setWindowsLF();
              addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent e) {
                        System.exit(0);
              setBounds(312,250,412,200);
              MyMenu menu = new MyMenu("File");
              MyMenu menu2 = new MyMenu("Help");
              menu.add(new JMenuItem("Try"));
              MyToolBar tb = new MyToolBar();
              tb.firePropertyChange("JToolBar.isRollover", false, true); 
              tb.add(menu);
              tb.add(menu2);
              JToggleButton jt = new JToggleButton("Toggle button", new ImageIcon("tog.gif"));
              jt.setFocusPainted(false);
              tb.add(jt);
              tb.addSeparator();
              JButton jb = new JButton("Button", new ImageIcon("but.gif"));
              jb.setFocusPainted(false);
              tb.add(jb);
              getContentPane().add(tb, BorderLayout.NORTH);     
              setVisible(true);
         public static final void setWindowsLF() {
              try {
                   UIManager.setLookAndFeel(windowsUI);
                   UIManager.put("MenuUI", "MyWindowsMenuUI");
              catch (Exception exc) {
                   System.err.println("Error loading L&F: " + exc);
         public static void main(String[] args) {
              new MenuToolBar();
    }Execute that, to see if the result is OK for you!
    Another thing : could you please report my name if you use and distribute the code ?
    Tell me if this helps you!
    Denis
    [                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Drop down buttons from a JToolBar

    I've been looking at various postings on how to get drop down options from a JToolBar. What I have seen suggests using JPopupMenu.
    However for my requirements I simply want the drop down buttons to appear in a gridlayout rather than as a drop down menu. Just the icons with no labels.
    Is it possible to change the layout manager up JPopupMenu or should I be trying some other component?
    The code I am trying looks something like that below where I demonstrate a toolbar dropdown color picker. The change of the layout manager seems to have no effect.
    final JButton standardColorButton = _toolBar.add(_actionStandardColor);
    final JButton changeColorButton = new JButton(_actionChangeStandardColor);
    _toolBar.add(changeColorButton);
    changeColorButton.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            int height = standardColorButton.getPreferredSize().height;
            JPopupMenu popup = new JPopupMenu("test");
            popup.add(_actionRed);
            popup.add(_actionGreen);
            popup.add(_actionBlue);
            popup.add(_actionBlack);
            popup.show(associationButton, 0, height);
            popup.setLayout(new GridLayout(0,2));

    Hi Vijay,
    Is this correct?
       var oInput = new sap.ui.commons.DropdownBox("ddlb_matnr");
           var oItemTemplate = new sap.ui.core.ListItem();
           oItemTemplate.bindProperty("key", "Matnr");
           oItemTemplate.bindProperty("text", "Description);     
           oInput.bindItems("/sap/opu/odata/sap/Z_MATNR_F4_SRV/materialSet", oItemTemplate, null, "'');
    This should work ?
    I tried this.. it is not fetching...         
    Let me know?

  • Want to create some button like font color button in MS Word?

    hi all
    i am writing a editor like MS Word, but small version with some basic functions: font family, font size, bold, italic... and font color.
    so i need some UI for font color similar to the one in MS Word.
    now i created a panel with two button; one shows the current color, and another show up JColorChooser when it is clicked; called JColorButton.
    now the problem i am having now is i created the icon similar to the down-arrow in JComboBox. but the size of that arrow changes depending on Look & feel and i could not able to make it similar to it for my own created button.
    any suggestion? ideas? i really appreciate it.
    currently,i am trying to get the image of down-arrow from JComboBox on the fly. but no luck yet.

    hi there,
    thanks a lot for reply.
    i checked BasicArrowButton. I replaced it with my JColorButton as second one, like in MS Word or Back button in Internet Explorer. but the size of arrow is smaller than the one in JComboBox beside it because the size of that button is smaller than JComboBox's size. so it still did not solve the problem yet.
    i wonder if there is any button which function the same as Font color button in MS word or Back button in Internet Explorer.
    or is there any way i can get the information about L&F about arrow of JComboBox?
    and also i make JToolBar to be rollover, so the border of button show only when the mouse is over. but how can i do this same affect on my JColorButton, which is a panel with two buttons in it.
    thanks a lot. i really appreciate it.

  • Simulating visual behaviour of buttons on button bar, like Firefox.

    I want to introduce visual behaviour like the Firefox button bar, where the buttons display with no background and no border, until you mouse over them.
    I have a panel that I use to display a button bar. The buttons on the button bar are instances of JButton.
    I can use jButton.setBorderPainted(false) and jButton.setBorder(null) to turn off the button frame.
    However, when using a look and feel, set by UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()), then the borders always paint.
    How can I turn off the borders and background for these buttons?

    On windows xp platform
    use JToolBar instead of panel, look at the code below and try to run it on windows xp platform
    import javax.swing.UIManager;
    public class NewJFrame extends javax.swing.JFrame
        public NewJFrame()
            initComponents();   
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
            jPopupMenu1 = new javax.swing.JPopupMenu();
            jMenuItem1 = new javax.swing.JMenuItem();
            jToolBar1 = new javax.swing.JToolBar();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            jButton3 = new javax.swing.JButton();
            jMenuItem1.setText("Item");
            jPopupMenu1.add(jMenuItem1);
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jToolBar1.setRollover(true);
            jButton1.setText("jButton1");
            jButton1.setFocusable(false);
            jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
            jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
            jToolBar1.add(jButton1);
            jButton2.setText("jButton2");
            jButton2.setFocusable(false);
            jButton2.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
            jButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
            jToolBar1.add(jButton2);
            jButton3.setText("jButton3");
            jButton3.setFocusable(false);
            jButton3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
            jButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
            jToolBar1.add(jButton3);
            getContentPane().add(jToolBar1, java.awt.BorderLayout.NORTH);
            pack();
        }// </editor-fold>
        * @param args the command line arguments
        public static void main(String args[]) {
            try
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            catch(Exception e)
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new NewJFrame().setVisible(true);
        // Variables declaration - do not modify
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JButton jButton3;
        private javax.swing.JMenuItem jMenuItem1;
        private javax.swing.JPopupMenu jPopupMenu1;
        private javax.swing.JToolBar jToolBar1;
        // End of variables declaration
    }

  • Malicious or not? Message popped up: Mozilla security found (something like too much, forget exact word) activity on your computer so it will do a fast scan of system file. With OK button.

    I was looking at youtube.com, which always tells me my browser is not supported and recommends I download Firefox, but that is what I was using, so I went to Firefox to check for updates. (I think I also had freecycle.org open.) Then this message popped up in a new page: Mozilla security found (something like "too much", forget exact word) activity on your computer so it will do a fast scan of system file. There was an OK button. The page address was: http://update17.stegner.ce.ms/index.php?Q7Lhl9ShbRxGJXpkM1VLSi4ZE8H4pTedoVPySgeppM3VpC+thEspcFG7qxHgn1pdsC2h5ygPGWI3t5hXqMzL9EQaZZ3J1e3CKXgCb0Qp. I did not click OK but copied the link and closed the window which closed the internet. I have never seen this before and would like to know if it is really Mozilla or possibly something malicious. Thank you.

    Good catch. That almost certainly is an invitation to download malware.
    There are a lot of infected web sites pushing "fake antivirus" software. If you have any doubts about whether your system might have become infected, you can supplement your regular security software with these two highly regarded scanners:
    Malwarebytes Anti-malware : http://www.malwarebytes.org/mbam.php
    SUPERAntiSpyware : http://www.superantispyware.com/

  • Hi it's me rabia and i'm apple user  I want to change my cell phone because it's having scratches on it and i also feel like its home button did't work correctly  So i want to know that can i have a new cell phone on replace of this one at any nearby of m

    Hi it's me rabia and i'm apple user
    I want to change my cell phone because it's having scratches on it and i also feel like its home button did't work correctly
    So i want to know that can i have a new cell phone on replace of this one at any nearby of my house App store without any cost  ?
    But i'm not having any line yet on my phone i use it on net mostly so what is the scene can i have or can't ??
    please inform me soon !

    Is your phone still covered by warranty?  If so, go to your nearest Apple store and depending on what happened, this may or may not be covered by warranty.  If it is, then you can get a replacement exactly as the phone you already have.
    If out of warranty, then there is nothing you can do and you'll have to pay.

  • How do I create an mail button in my site? (Like, for sharing the site to a friend, not to the site administrator)

    I would like someone to be able to share my site to their friends so the friend receives an emailed link, preferable with a logo and strap line.
    Thanks guys
    Jimmy

    Hi Jimmy,
    there are numbers of option available online, try these
    Share Buttons | AddThis
    ShareThis' Social Media Buttons Optimize Brand and Publisher Content

  • Something has happen my ipad air 2 it wont let me download or update any apps, when I press the button do update or download it looks like it is but it doesn't so if anyone knows what's going wind please help me

    Something has happen my ipad air 2 it wont let me download or update any apps, when I press the button do update or download it looks like it is but it doesn't so if anyone knows what's going wind please help me

    Do you have any restrictions for purchasing apps on the phone? Settings > General > Restrictions. If you have a Mac computer or another Apple device can you purchase things in the App Store using the same Apple ID on something else?

  • I have downloaded updates for Firefox but my browser doesn't look like it should, no single menu button etc, how do I get it to look like your demo?

    The last few times I have been prompted to update my firefox for desktop, my browser has not looked any different even though I get notification to say updates completed successfully. When I update firefox gives a demo of new features and how my browser should look, mine has not looked like the demo for the past few updates. It's annoying because I really like the look of having just one menu button. How can I change the look of my browser?

    The Firefox button displays by default only in Windows Vista and Windows 7. You '''''can''''' have it display in Windows XP
    '''Menu Bar'''<br />
    *right-click empty space at the end of the Tab Bar, click "Menu Bar" to place a checkmark
    *Menu Bar checked = Menu Bar on; Firefox button off
    *Menu Bar un-checked = Menu Bar off; Firefox button on
    *Other methods of doing the same:
    **click Firefox button > Options, click Menu Bar
    **Quick toggle Menu Bar on/off: ALT+V+T+M
    To have the Menu Bar '''''temporarily''''' display when the Firefox button is on, press the ALT key or the F10 key to make the Menu Bar appear and use your mouse to make selections from the temporarily displayed Menu Bar. Why would you want to do this? The selections available are different.
    '''If this reply solves your problem, please click "Solved It" next to this reply when <u>signed-in</u> to the forum.'''

  • When I try to play a flash video (like youtube) i have to click a flash button several times before it works. Why do flash videos not recogonize any clicks without several tries first?

    When I try to go to a flash video, the video player never seems to recognize my mouse clicks without several tries.
    It's hard to explain but if I'm at a youtube video and i place my cursor over the button that lets you skip around the video, the cursor will alternate being a cursor (like its not recognized) and a hand like its supposed to. It's sort of keeps flickering between the two if I move the mouse around on that little skip button.
    I tried uninstalling firefox but it didn't make a difference. I noticed it after updating to the newer firefoxe updates. This does not happen under IE.
    thank you for your help.

    '''[https://support.mozilla.org/en-US/kb/troubleshoot-firefox-issues-using-safe-mode Start Firefox in Safe Mode]''' {web link}
    While you are in safe mode;
    Press the '''Alt''' or '''F10''' key to bring up the tool bar.
    Followed by;
    Windows; '''Tools > Options'''
    Linux; '''Edit > Preferences'''
    Mac; ''application name'' '''> Preferences'''
    Then '''Advanced > General.'''
    Look for and turn off '''Use Hardware Acceleration'''.
    Poke around safe web sites and see if there is still a problem. Then restart.

  • Inside the browser, right click on the mouse seems to be disabled. How can I enable the right click button? It works fine on toolbars and tab bar but not inside tabs or windows. I would like to be able to copy and paste and such. Thank you

    Right mouse button does not open any menu when clicked inside of tabs or windows. Works properly on the toolbars, in the address line, search bar...etc. but has no action on the page I'm browsing. I purchased a mouse recently and like the old one, the right button works in all other areas of my operating system. I would like to know if there is a setting in firefox that I can change to correct this.

    There are also websites that can disable the right-click context menu.
    See Tools > Options > Content : JavaScript > Advanced > Allow Scripts to:
    [ ] "Disable or replace context menus"
    There are other things that need attention:
    Your above posted system details show outdated plugin(s) with known security and stability risks that you should update.
    *Shockwave Flash 10.0 r42
    Update the [[Managing the Flash plugin|Flash]] plugin to the latest version.
    *http://www.adobe.com/software/flash/about/

Maybe you are looking for