因此,出于某种原因,有时翻转选择会在快速从一个菜单项移动到另一个菜单项时发出错误:
我只使用所有默认值,这是一个java错误吗?或者我做错了什么? 以下是一些可编译的代码:
import java.awt.*;
import javax.swing.Box;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class example {
static JFrame frame;
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
frame = new JFrame("~Module Logger~");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setPreferredSize(new Dimension(550,325));
//Add Menu Bar Components
JMenuBar menuBar = new JMenuBar();
JMenu file, pointTo, helpBar, moduleCommands;
file = new JMenu("File");
moduleCommands = new JMenu("Module Commands");
JMenuItem about,clearAutocomplete, help, pointToTest, pointToLive, reset;
about = new JMenuItem("About");
clearAutocomplete = new JMenuItem("Clear Autocomplete Data");
pointTo = new JMenu("Point to Server...");
helpBar = new JMenu("Help");
pointToTest = new JMenuItem("Test Server");
pointToLive = new JMenuItem("Live Server");
reset = new JMenuItem("Reset Module");
help = new JMenuItem("Help Menu");
pointTo.add(pointToTest);
pointTo.add( Box.createVerticalStrut( 3 ) );
pointTo.add(pointToLive);
file.add(clearAutocomplete);
file.add( Box.createVerticalStrut( 3 ) );
file.add(about);
moduleCommands.add(reset);
moduleCommands.add( Box.createVerticalStrut( 3 ) );
moduleCommands.add(pointTo);
helpBar.add(help);
menuBar.add(file);
menuBar.add(moduleCommands);
menuBar.add(helpBar);
frame.setJMenuBar(menuBar);
//Set up the content pane.
//addComponentsToPane(frame.getContentPane());
//Display the window.
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
提前致谢!