本文整理匯總了Java中javax.swing.MenuElement.getSubElements方法的典型用法代碼示例。如果您正苦於以下問題:Java MenuElement.getSubElements方法的具體用法?Java MenuElement.getSubElements怎麽用?Java MenuElement.getSubElements使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.MenuElement
的用法示例。
在下文中一共展示了MenuElement.getSubElements方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: launch
import javax.swing.MenuElement; //導入方法依賴的package包/類
@Override
public MenuElement launch() {
MenuElement element = getMenuElement();
if (element != null) {
MenuElement[] subElements = element.getSubElements();
for (MenuElement subElement : subElements) {
if (((Component) subElement).isShowing()
&& ((Component) subElement).isEnabled()
&& chooser.checkPathComponent(depth, subElement)) {
process(subElement);
return subElement;
}
if (stopped) {
return null;
}
}
}
return null;
}
示例2: attachActionListener
import javax.swing.MenuElement; //導入方法依賴的package包/類
/**
* Recursively attach the given action listener to all items in the
* given menu that have a non-<code>null</code> action command
*
* @param menuElement The menu element
* @param actionListener The action listener
*/
private static void attachActionListener(
MenuElement menuElement, ActionListener actionListener)
{
if (menuElement instanceof JMenuItem)
{
JMenuItem menuItem = (JMenuItem)menuElement;
if (menuItem.getActionCommand() != null)
{
menuItem.addActionListener(actionListener);
}
}
MenuElement[] subElements = menuElement.getSubElements();
for (MenuElement subElement : subElements)
{
attachActionListener(subElement, actionListener);
}
}
示例3: actionPerformed
import javax.swing.MenuElement; //導入方法依賴的package包/類
public void actionPerformed(final ActionEvent e) {
final MenuElement[] path = getSelectedPath();
if (path.length > 3 || path[0] instanceof JPopupMenu) {
final MenuElement lastElement = path[path.length - 1];
final MenuElement[] subElements = lastElement.getSubElements();
if (!Utilities.isEmptyArray(subElements)) {
MenuElement[] newPath;
final MenuElement newSelectedItem = subElements[0];
final MenuElement newSelectedChild = Utilities.getFirstSelectableItem(newSelectedItem.getSubElements());
if (newSelectedItem instanceof JPopupMenu && newSelectedChild != null) {
newPath = derivePath(path, path.length + 2, path.length);
newPath[path.length + 1] = newSelectedChild;
} else {
newPath = derivePath(path, path.length + 1, path.length);
}
newPath[path.length] = newSelectedItem;
setSelectedPath(newPath);
return;
}
}
selectNextTopLevelMenu(path);
}
示例4: findScraperAction
import javax.swing.MenuElement; //導入方法依賴的package包/類
private Action findScraperAction(MenuElement scrapeMenu, String scraperKey) {
if (scrapeMenu instanceof JMenuItem) {
JMenuItem menuItem = (JMenuItem) scrapeMenu;
Action action = menuItem.getAction();
if (action != null) {
String key = (String) action.getValue(ScrapeAmalgamatedAction.SCRAPE_KEY);
if (key != null && key.equals(scraperKey)) {
return action;
}
}
}
for (MenuElement childMenu : scrapeMenu.getSubElements()) {
Action childAction = findScraperAction(childMenu, scraperKey);
if (childAction != null) {
return childAction;
}
}
return null;
}
示例5: installListener
import javax.swing.MenuElement; //導入方法依賴的package包/類
public static <T> void installListener(MenuElement menu, PopupSelectionListener<T> listener)
{
for(MenuElement element : menu.getSubElements())
{
if(element instanceof JMenuItem)
{
final JMenuItem item = (JMenuItem) element;
for(ActionListener l : item.getActionListeners())
item.removeActionListener(l);
item.addActionListener((event) -> {
T userData = getUserData(item);
if(userData != null)
listener.itemSelected(userData);
});
}
installListener(element, listener);
}
}
示例6: getSelectedElement
import javax.swing.MenuElement; //導入方法依賴的package包/類
private static MenuElement getSelectedElement(MenuElement bar) {
MenuElement[] subElements = bar.getSubElements();
for (MenuElement subElement : subElements) {
if (subElement instanceof JMenu
&& ((JMenu) subElement).isSelected()) {
return subElement;
} else if (subElement instanceof JMenuItem
&& ((JMenuItem) subElement).isSelected()) {
return subElement;
}
}
return null;
}
示例7: componentsInMenu
import javax.swing.MenuElement; //導入方法依賴的package包/類
private List<Component> componentsInMenu(MenuElement menuElement) {
List<Component> list = new ArrayList<Component>();
for (MenuElement element : menuElement.getSubElements()) {
list.add(element.getComponent());
}
return list;
}
示例8: isMenuSubElement
import javax.swing.MenuElement; //導入方法依賴的package包/類
/**
* Returns if <code>element</code> is the subElement of <code>container</code>.
*
* @param container menu to look for sub element at
* @param element element to check
* @return <code>true</code> if <code>element</code> is the subElement of <code>container</code>,
* <code>false</code> otherwise
*/
public static boolean isMenuSubElement(final MenuElement container, final MenuElement element) {
final MenuElement[] subElements = container.getSubElements();
for (int i = 0; i < subElements.length; i++) {
if (subElements[i] == element) {
return true;
}
}
return false;
}
示例9: setActionsMenu
import javax.swing.MenuElement; //導入方法依賴的package包/類
private static void setActionsMenu(JDialog dialog, MenuElement menu) {
MenuElement[] subItems = menu.getSubElements();
InputMap inputMap = dialog.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
for (MenuElement menuElement : subItems) {
if (menuElement instanceof JMenuItem) {
final JMenuItem menuItem = (JMenuItem) menuElement;
if (menuItem.getAccelerator() != null) {
String key = "hackAction" + counter++;
inputMap.put(menuItem.getAccelerator(), key);
if (menuItem.getAction() == null) {
dialog.getRootPane().getActionMap().put(key,
new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
menuItem.doClick();
}
});
} else {
dialog.getRootPane().getActionMap().put(key,
menuItem.getAction());
}
// System.out.println(key + " : "
// + menuItem.getText()+ " : "
// + menuItem.getActionCommand() + " : "
// + menuItem.getAccelerator() + " : "
// + menuItem.getAction());
}
}
// the original code had an else condition here, which is wrong.
// JMenu is a subclass of JMenuItem, which prevents sub-menus from being traversed.
if (menuElement.getSubElements().length > 0) {
setActionsMenu(dialog, menuElement);
}
}
}
示例10: createDisabledIconsForMenuEntries
import javax.swing.MenuElement; //導入方法依賴的package包/類
/**
* Creates icons for the disabled state for all JMenuItems with FontBasedIcons in the given menuElement.
* This is necessary as Swing is not able to generate default disabled icons for font based icons.
*
* @param menuElement the menuElement for which disabled icons should be generated
*/
public void createDisabledIconsForMenuEntries(MenuElement menuElement) {
for (MenuElement subElement : menuElement.getSubElements()) {
if ((subElement instanceof JMenu) || (subElement instanceof JPopupMenu)) {
createDisabledIconsForMenuEntries(subElement);
} else if (subElement instanceof JMenuItem) {
JMenuItem item = (JMenuItem) subElement;
if (item.getIcon() instanceof IconTheme.FontBasedIcon) {
item.setDisabledIcon(((IconTheme.FontBasedIcon) item.getIcon()).createDisabledIcon());
}
}
}
}
示例11: appendMenuSubElements
import javax.swing.MenuElement; //導入方法依賴的package包/類
private static void appendMenuSubElements(MenuElement element, StringBuilder builder, String indent) {
for (MenuElement subItem : element.getSubElements()) {
appendMenuItem((Component)subItem, builder, indent);
}
}