这是我正在使用的代码:
JMenu menu = new JMenu("Menu");
JMenuItem item = new JMenuItem("Add");
item.add(new JButton("SOMETHING A BIT WORDY"));
menu.add(item);
// ...
JMenuBar menuBar = new JMenuBar();
menuBar.addMenu(menu);
JFrame frame = new JFrame();
frame.setJMenuBar(menuBar);
// ...
frame.pack();
frame.setVisible();
但是,按钮(在菜单项内部)看起来很小,并且仅包含文本“...”,当按钮的大小无法适合预期的文本时使用该文本。有没有办法让我的 JMenuItem “增长”以适合我的 JButton(或 JTextArea,或 JLabel,或任何可能的组件)?