本文整理匯總了Java中javax.swing.JMenuBar類的典型用法代碼示例。如果您正苦於以下問題:Java JMenuBar類的具體用法?Java JMenuBar怎麽用?Java JMenuBar使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JMenuBar類屬於javax.swing包,在下文中一共展示了JMenuBar類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: postProcessKeyEvent
import javax.swing.JMenuBar; //導入依賴的package包/類
public boolean postProcessKeyEvent(KeyEvent ev) {
if (ev.isConsumed())
return false;
if (processShortcut(ev))
return true;
Window w = SwingUtilities.windowForComponent(ev.getComponent());
if (w instanceof Dialog && !WindowManagerImpl.isSeparateWindow(w))
return false;
JFrame mw = (JFrame)WindowManagerImpl.getInstance().getMainWindow();
if (w == mw) {
return false;
}
JMenuBar mb = mw.getJMenuBar();
if (mb == null)
return false;
boolean pressed = (ev.getID() == KeyEvent.KEY_PRESSED);
boolean res = invokeProcessKeyBindingsForAllComponents(ev, mw, pressed);
if (res)
ev.consume();
return res;
}
示例2: init
import javax.swing.JMenuBar; //導入依賴的package包/類
@Override
public void init() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
JMenuBar bar = new JMenuBar();
JMenu menu = new JMenu("Menu");
JCheckBoxMenuItem checkBoxMenuItem
= new JCheckBoxMenuItem("JCheckBoxMenuItem");
checkBoxMenuItem.setSelected(true);
menu.add(checkBoxMenuItem);
bar.add(menu);
setJMenuBar(bar);
}
});
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例3: getFittingMenubar
import javax.swing.JMenuBar; //導入依賴的package包/類
private void getFittingMenubar(String mode) {
JMenuBar jmb = new JMenuBar();
JMenuItem[][] menuItems = { { new JMenuItem(FI_FILE_NEW), null, new JMenuItem(FI_FILE_EXIT) },
{ new JMenuItem(FI_HELP), null, new JMenuItem(FI_ABOUT) } };
String[] menuTitles = { "File", "Help" };
char[] chars = { 'F', 'e' };
for (int i = 0; i < menuItems.length; i++) {
JMenu menu = new JMenu(menuTitles[i]);
menu.setMnemonic(chars[i]);
for (int j = 0; j < menuItems[i].length; j++) {
if (menuItems[i][j] == null) {
menu.addSeparator();
} else {
menu.add(menuItems[i][j]);
if (i == 0 && (j == 0 && mode.equals("demo"))) {
menuItems[i][j].setEnabled(false);
}
}
}
jmb.add(menu);
}
setMenuBar(jmb);
}
示例4: createAndShowGUI
import javax.swing.JMenuBar; //導入依賴的package包/類
private static void createAndShowGUI(TestItem testItem) {
frame = new JFrame();
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar menuBar = new JMenuBar();
menu = new JMenu("Menu");
JMenuItem menuItem = testItem.getMenuItem();
testItem.setProperties(menuItem);
menu.add(menuItem);
menuBar.add(menu);
frame.setJMenuBar(menuBar);
frame.setVisible(true);
}
示例5: createGUI
import javax.swing.JMenuBar; //導入依賴的package包/類
private static JFrame createGUI() {
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("Some menu");
menuBar.add(menu);
for (int i = 0; i < 10; i++) {
menu.add(new JMenuItem("Some menu #" + i));
}
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setMinimumSize(new Dimension(200, 200));
frame.setJMenuBar(menuBar);
return frame;
}
示例6: drawSelectedComponent
import javax.swing.JMenuBar; //導入依賴的package包/類
private void drawSelectedComponent(Graphics2D g2, JComponent selected, RADComponent rad) {
if(selected == null) return;
if(selected.getParent() == null || !selected.getParent().isVisible()) return;
// draw normal border around toplevel menus
if (selected instanceof JMenu && selected.getParent() instanceof JMenuBar) {
JMenuItem menu = (JMenuItem) selected;
Point location = SwingUtilities.convertPoint(menu, new Point(0, 0), this);
g2.translate(location.x, location.y);
// #114610: keep drop rectangle guidelines consistent when menu component is inserted from menu-bar into submenu
g2.setStroke((currentTargetType == DropTargetType.INTO_SUBMENU) ? DROP_TARGET_LINE_STROKE : SELECTION_STROKE);
g2.setColor(SELECTION_COLOR);
g2.drawRect(0, 0, menu.getWidth() - 1, menu.getHeight() - 1);
g2.translate(-location.x, -location.y);
}
// style only menuitems and menus that aren't also toplevel menus
// don't do subrect drawing if doing a drag
if (selected instanceof JMenuItem && !(selected.getParent() instanceof JMenuBar) && currentTargetComponent == null) {
JMenuItem item = (JMenuItem) selected;
drawSubselectedItem(g2, item);
}
}
示例7: altPressed
import javax.swing.JMenuBar; //導入依賴的package包/類
void altPressed(KeyEvent ev) {
MenuSelectionManager msm =
MenuSelectionManager.defaultManager();
MenuElement[] path = msm.getSelectedPath();
if (path.length > 0 && ! (path[0] instanceof ComboPopup)) {
msm.clearSelectedPath();
menuCanceledOnPress = true;
ev.consume();
} else if(path.length > 0) { // We are in ComboBox
menuCanceledOnPress = false;
WindowsLookAndFeel.setMnemonicHidden(false);
WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
ev.consume();
} else {
menuCanceledOnPress = false;
WindowsLookAndFeel.setMnemonicHidden(false);
WindowsGraphicsUtils.repaintMnemonicsInWindow(winAncestor);
JMenuBar mbar = root != null ? root.getJMenuBar() : null;
if(mbar == null && winAncestor instanceof JFrame) {
mbar = ((JFrame)winAncestor).getJMenuBar();
}
JMenu menu = mbar != null ? mbar.getMenu(0) : null;
if(menu != null) {
ev.consume();
}
}
}
示例8: setDefaultMenuBar
import javax.swing.JMenuBar; //導入依賴的package包/類
void setDefaultMenuBar(final JMenuBar menuBar) {
installDefaultMenuBar(menuBar);
// scan the current frames, and see if any are foreground
final Frame[] frames = Frame.getFrames();
for (final Frame frame : frames) {
if (frame.isVisible() && !isFrameMinimized(frame)) {
return;
}
}
// if we have no foreground frames, then we have to "kick" the menubar
final JFrame pingFrame = new JFrame();
pingFrame.getRootPane().putClientProperty("Window.alpha", Float.valueOf(0.0f));
pingFrame.setUndecorated(true);
pingFrame.setVisible(true);
pingFrame.toFront();
pingFrame.setVisible(false);
pingFrame.dispose();
}
示例9: start
import javax.swing.JMenuBar; //導入依賴的package包/類
private void start(DropTargetDragEvent dtde) {
PaletteItem item = PaletteUtils.getSelectedItem();
if(item != null && !isMenuRelatedComponentClass(item.getComponentClass())) {
hideMenuLayer();
return;
}
if(formDesigner.getDesignerMode() == FormDesigner.MODE_ADD && item != null) {
if(JMenuBar.class.isAssignableFrom(item.getComponentClass())) {
hideMenuLayer();
return;
}
dragop.start(item,dtde.getLocation());
}
}
示例10: getMenuBarArrayList
import javax.swing.JMenuBar; //導入依賴的package包/類
/** Get MenuBar and tranfer it to ArrayList.
* @param menu menu to be tranfered
* @return tranfered menubar */
private static List<NbMenu> getMenuBarArrayList(JMenuBar menu) {
visitMenuBar(menu);
MenuElement [] elements = menu.getSubElements();
List<NbMenu> list = new ArrayList<NbMenu>();
for(int k=0; k < elements.length; k++) {
// if(elements[k] instanceof JMenuItem) {
// list.add(new NbMenu((JMenuItem)elements[k], null));
JMenuBarOperator menuOp = new JMenuBarOperator(menu);
JMenu item = menuOp.getMenu(k);
list.add(new NbMenu(item, getMenuArrayList(item)));
// }
/*if(elements[k] instanceof JMenuBar) {
JMenuBarOperator menuOp = new JMenuBarOperator(menu);
list.add(getMenuArrayList(menuOp.getMenu(0)));
}
*/
}
return list;
}
示例11: visitMenuBar
import javax.swing.JMenuBar; //導入依賴的package包/類
/** Open all menus in menubar
* @param menu to be visited */
public static void visitMenuBar(JMenuBar menu) {
MenuElement[] elements = menu.getSubElements();
JMenuBarOperator op = new JMenuBarOperator(menu);
for (int k = 0; k < elements.length; k++) {
if (elements[k] instanceof JMenuItem) {
op.pushMenu(((JMenuItem) elements[k]).getText(), "/", true, true);
try {
op.wait(200);
} catch (Exception e) {
}
}
}
}
示例12: getMenuBarArrayList
import javax.swing.JMenuBar; //導入依賴的package包/類
/** Get MenuBar and tranfer it to ArrayList.
* @param menu menu to be tranfered
* @return tranfered menubar - !separator is ignored
*/
public static ArrayList<NbMenuItem> getMenuBarArrayList(JMenuBar menu) {
// System.out.println("getMenuBarArrayList " + menu.getName());
visitMenuBar(menu);
MenuElement[] elements = menu.getSubElements();
ArrayList<NbMenuItem> list = new ArrayList<NbMenuItem>();
for (int k = 0; k < elements.length; k++) {
if (elements[k] instanceof JPopupMenu.Separator) {
NbMenuItem separator = new NbMenuItem();
separator.setSeparator(true);
list.add(separator);
} else {
if (elements[k] instanceof JMenuItem) {
NbMenuItem item = new NbMenuItem((JMenuItem) elements[k]);
JMenuBarOperator menuOp = new JMenuBarOperator(menu);
item.setSubmenu(getMenuArrayList(menuOp.getMenu(k)));
list.add(item);
}
}
}
return list;
}
示例13: getTrafficMenubar
import javax.swing.JMenuBar; //導入依賴的package包/類
private void getTrafficMenubar() {
JMenuBar jmb = new JMenuBar();
JMenuItem[][] menuItems = { { new JMenuItem(TR_FILE_NEW), null, new JMenuItem(TR_FILE_EXIT) },
{ new JMenuItem(TR_HELP), null, new JMenuItem(TR_ABOUT) } };
String[] menuTitles = { "File", "Help" };
char[] chars = { 'F', 'e' };
for (int i = 0; i < menuItems.length; i++) {
JMenu menu = new JMenu(menuTitles[i]);
menu.setMnemonic(chars[i]);
for (int j = 0; j < menuItems[i].length; j++) {
if (menuItems[i][j] == null) {
menu.addSeparator();
} else {
menu.add(menuItems[i][j]);
}
}
jmb.add(menu);
}
setMenuBar(jmb);
}
示例14: makeMenubar
import javax.swing.JMenuBar; //導入依賴的package包/類
/**
* Creates workload analysis menu
* @return menu
*/
public void makeMenubar() {
workloadMenubar = new JMenuBar();
JMenuItem[][] menuItems = { { new JMenuItem(HELP),null,new JMenuItem(HELP_CREDITS) } };
String[] menuTitles = { "Help" };
char[] chars = { 'e' };
for (int i = 0; i < menuItems.length; i++) {
JMenu menu = new JMenu(menuTitles[i]);
menu.setMnemonic(chars[i]);
for (int j = 0; j < menuItems[i].length; j++) {
if (menuItems[i][j] == null) {
menu.addSeparator();
} else {
menu.add(menuItems[i][j]);
}
}
workloadMenubar.add(menu);
}
parent.setMenuBar(workloadMenubar);
}
示例15: InputFrame
import javax.swing.JMenuBar; //導入依賴的package包/類
public InputFrame(){
panel = new InputPanel(254);
Container c = this.getContentPane();
c.setLayout(new BorderLayout());
c.add(new JScrollPane(panel), BorderLayout.CENTER);
JButton jb = new JButton("Transfer");
//add menu bar
JMenuBar jmb = new JMenuBar();
JMenu menu = new JMenu("File");
jmb.add(menu);
initMenuItems(); //! da drin schreiben (und im InputPanel)
menu.add(miSave);
menu.add(miSaveAs);
menu.add(miLoad);
menu.addSeparator(); //! ...trennstrich im menü, dann dein item
menu.add(miExport);
this.setJMenuBar(jmb);
}