/** * adds a {@link com.tomtessier.scrollabledesktop.BaseRadioButtonMenuItem BaseRadioButtonMenuItem} * to the menu and associates it with an internal frame * * @param associatedFrame the internal frame to associate with the menu item */ public void add(BaseInternalFrame associatedFrame) { int displayedCount = getItemCount() - baseItemsEndIndex + 1; int currentMenuCount = displayedCount; // compute the key mnemonic based upon the currentMenuCount if (currentMenuCount > 9) { currentMenuCount /= 10; } BaseRadioButtonMenuItem menuButton = new BaseRadioButtonMenuItem( this, displayedCount + " " + associatedFrame.getTitle(), KeyEvent.VK_0 + currentMenuCount, -1, true, associatedFrame); associatedFrame.setAssociatedMenuButton(menuButton); add(menuButton); frameRadioButtonMenuItemGroup.add(menuButton); menuButton.setSelected(true); // and reselect here, so that the // buttongroup recognizes the change }
private void refreshMenu() { // refresh the associated mnemonics, so that the keyboard shortcut // keys are properly renumbered... // get an enumeration to the elements of the current button group Enumeration e = frameRadioButtonMenuItemGroup.getElements(); int displayedCount = 1; int currentMenuCount = 0; while (e.hasMoreElements()) { BaseRadioButtonMenuItem b = (BaseRadioButtonMenuItem) e.nextElement(); // compute the key mnemonic based upon the currentMenuCount currentMenuCount = displayedCount; if (currentMenuCount > 9) { currentMenuCount /= 10; } b.setMnemonic(KeyEvent.VK_0 + currentMenuCount); b.setText(displayedCount + " " + b.getAssociatedFrame().getTitle()); displayedCount++; } }