What I want to achieve is this:
The image means I want to put some button, like JMenuItem
, into the application menu bar (JMenuBar
) to allow toggling some operation. So I wrote such code:
// Start button
JMenuItem startbut = new JMenuItem();
startbut.setText("Start");
startbut.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
ToggleAction();
}
});
menuBar1.add(startbut);
But it doesn't act as expected:
Especially the white background is disturbing and looks broken.
Java GUI libraries have thousands options so I think there must be more valid way to do this. What should I do?