Tooltip for a JMenuItem

后端 未结 1 1786
自闭症患者
自闭症患者 2021-01-20 18:19

I add a menu to a toolbar like this :

    JMenuBar menu = new JMenuBar();
    JMenu actions = new JMenu(\"Aktionen\");
    Icon menuIcon = ImageUtilities.loa         


        
相关标签:
1条回答
  • 2021-01-20 19:00

    The sscce below works correctly. If you still have problems, please edit your question to include an example that exhibits the problem you describe.

    Addendum: I added the menu to a JToolBar, and it still works, either docked or free-floating.

    import java.awt.EventQueue;
    import javax.swing.JFrame;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.JToolBar;
    
    /** @see http://stackoverflow.com/a/14630345/230513 */
    public class Test {
    
        private void display() {
            JFrame f = new JFrame("Test");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JMenuBar menu = new JMenuBar();
            JMenu actions = new JMenu("Aktionen");
            JMenuItem addItem = new JMenuItem("Add");
            addItem.setToolTipText("Add new Item");
            menu.add(actions);
            actions.add(addItem);
            JToolBar toolbar = new JToolBar("Tools");
            toolbar.add(menu);
            f.add(toolbar);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        }
    
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    new Test().display();
                }
            });
        }
    }
    
    0 讨论(0)
提交回复
热议问题