本文整理汇总了Java中javax.swing.JPopupMenu.getComponentCount方法的典型用法代码示例。如果您正苦于以下问题:Java JPopupMenu.getComponentCount方法的具体用法?Java JPopupMenu.getComponentCount怎么用?Java JPopupMenu.getComponentCount使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.JPopupMenu
的用法示例。
在下文中一共展示了JPopupMenu.getComponentCount方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: displayPopup
import javax.swing.JPopupMenu; //导入方法依赖的package包/类
public void displayPopup() {
JPopupMenu menu = new JPopupMenu();
populatePopup(menu);
if (menu.getComponentCount() > 0) {
Dimension size = menu.getPreferredSize();
size.width = Math.max(size.width, getWidth());
menu.setPreferredSize(size);
menu.show(this, 0, getHeight());
}
}
示例2: showPopupMenu
import javax.swing.JPopupMenu; //导入方法依赖的package包/类
private void showPopupMenu(MouseEvent e) {
JPopupMenu popup = new JPopupMenu() {
public void setVisible(boolean visible) {
if (visible) popupShowing();
super.setVisible(visible);
if (!visible) popupHidden();
}
};
int row = getSelectedRow();
Object value = getValueForRow(row);
Object userValue = getUserValueForRow(row);
populatePopup(popup, value, userValue);
if (popup.getComponentCount() > 0) {
if (e == null) {
boolean b = row == -1;
int c = b ? -1 : convertColumnIndexToView(mainColumn);
Rectangle t = b ? getVisibleRect() : getCellRect(row, c, false);
Dimension s = popup.getPreferredSize();
int x = t.x + (t.width - s.width) / 2;
int y = t.y + (b ? (t.height - s.height) / 2 : getRowHeight() - 4);
popup.show(this, Math.max(x, 0), Math.max(y, 0));
} else {
popup.show(this, e.getX(), e.getY());
}
}
}
示例3: displayPopup
import javax.swing.JPopupMenu; //导入方法依赖的package包/类
protected void displayPopup() {
JPopupMenu menu = new JPopupMenu();
populatePopup(menu);
if (menu.getComponentCount() > 0) {
Dimension size = menu.getPreferredSize();
size.width = Math.max(size.width, getWidth());
menu.setPreferredSize(size);
int align = getPopupAlign();
int x;
switch (align) {
case SwingConstants.EAST:
case SwingConstants.NORTH_EAST:
case SwingConstants.SOUTH_EAST:
x = getWidth() - size.width;
break;
default:
x = 0;
break;
}
int y;
switch (align) {
case SwingConstants.NORTH:
case SwingConstants.NORTH_EAST:
case SwingConstants.NORTH_WEST:
y = -size.height;
break;
default:
y = getHeight();
break;
}
menu.show(this, x, y);
}
}
示例4: showPopup
import javax.swing.JPopupMenu; //导入方法依赖的package包/类
private void showPopup (Point e, Component invoker) {
int row = UnitTab.this.table.rowAtPoint (e);
if (row >= 0) {
table.getSelectionModel ().setSelectionInterval (row, row);
final JPopupMenu finalPopup = popupActionsSupport.createPopup ();
if (finalPopup != null && finalPopup.getComponentCount () > 0) {
finalPopup.show (invoker,e.x, e.y);
}
}
}
示例5: buildPopupForRoom
import javax.swing.JPopupMenu; //导入方法依赖的package包/类
public JPopupMenu buildPopupForRoom(Room room, JTree tree) {
JPopupMenu popup = new JPopupMenu();
for (RoomActionFactory f : roomActionFactories) {
popup.add(f.getAction(room, tree));
}
return popup.getComponentCount() == 0 ? null : popup;
}
示例6: buildPopupForPlayer
import javax.swing.JPopupMenu; //导入方法依赖的package包/类
public JPopupMenu buildPopupForPlayer(SimplePlayer target, JTree tree) {
JPopupMenu popup = new JPopupMenu();
for (PlayerActionFactory f : playerActionFactories) {
final Action a = f.getAction(target, tree);
if (a != null) {
popup.add(a);
}
}
return popup.getComponentCount() == 0 ? null : popup;
}
示例7: addShowHideItems
import javax.swing.JPopupMenu; //导入方法依赖的package包/类
/** Adds menu items for graying out. */
private void addShowHideItems(JPopupMenu result) {
// add the show/hide menu
@SuppressWarnings({"unchecked", "rawtypes"})
JPopupMenu restMenu = new ShowHideMenu(this.jGraph).getPopupMenu();
while (restMenu.getComponentCount() > 0) {
result.add(restMenu.getComponent(0));
}
}
示例8: setMenuText
import javax.swing.JPopupMenu; //导入方法依赖的package包/类
public static void setMenuText(final JPopupMenu menu) {
for (int i = 0; i < menu.getComponentCount(); i++) {
if (isParent(JMenuItem.class, menu.getComponent(i).getClass()))
setMenuItemText((JMenuItem) menu.getComponent(i));
else if (menu.getComponent(i).getClass() == JMenu.class)
setMenuText((JMenu) menu.getComponent(i));
else if (isParent(JRadioButtonMenuItem.class, menu.getComponent(i)
.getClass()))
setMenuItemText((JRadioButtonMenuItem) menu.getComponent(i));
}
}
示例9: configurePopupMenu
import javax.swing.JPopupMenu; //导入方法依赖的package包/类
/**
* Overridden to toggle the enabled state of various
* RSyntaxTextArea-specific menu items.
*
* If you set the popup menu via {@link #setPopupMenu(JPopupMenu)}, you
* will want to override this method, especially if you removed any of the
* menu items in the default popup menu.
*
* @param popupMenu The popup menu. This will never be <code>null</code>.
* @see #createPopupMenu()
* @see #setPopupMenu(JPopupMenu)
*/
@Override
protected void configurePopupMenu(JPopupMenu popupMenu) {
super.configurePopupMenu(popupMenu);
// They may have overridden createPopupMenu()...
if (popupMenu!=null && popupMenu.getComponentCount()>0 &&
foldingMenu!=null) {
foldingMenu.setEnabled(foldManager.
isCodeFoldingSupportedAndEnabled());
}
}
示例10: getPopupMenuItem
import javax.swing.JPopupMenu; //导入方法依赖的package包/类
/**
* Returns the index of an item in a popup menu.
*
* @param menu the menu.
* @param text the label.
*
* @return The item index.
*/
private int getPopupMenuItem(JPopupMenu menu, String text) {
int index = -1;
for (int i = 0; (index == -1) && (i < menu.getComponentCount()); i++) {
Component comp = menu.getComponent(i);
if (comp instanceof JMenuItem) {
JMenuItem item = (JMenuItem) comp;
if (text.equals(item.getText())) {
index = i;
}
}
}
return index;
}
示例11: buildPopup
import javax.swing.JPopupMenu; //导入方法依赖的package包/类
protected JPopupMenu buildPopup() {
JPopupMenu popup = new JPopupMenu();
return popup.getComponentCount() > 0 ? popup : null;
}
示例12: actionPerformed
import javax.swing.JPopupMenu; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent evt){
if(annotationEditor == null) return;
//this action either creates a new annotation or starts editing an
//existing one. In either case we need first to make sure that the current
//annotation is finished editing.
if(!annotationEditor.editingFinished()) return;
if(textLocation == -1) return;
JPopupMenu popup = new JPopupMenu();
//check for selection hovering
if(textPane.getSelectedText() != null
&& textPane.getSelectionStart() <= textLocation
&& textPane.getSelectionEnd() >= textLocation){
//add 'New annotation' to the popup menu
popup.add(new NewAnnotationAction(textPane.getSelectedText()));
popup.addSeparator();
}
//check for annotations at location
for(SetHandler setHandler : setHandlers) {
for(Annotation ann : setHandler.set.get(
Math.max(0l, textLocation-1),
Math.min(document.getContent().size(), textLocation+1))) {
if(setHandler.getTypeHandler(ann.getType()).isSelected()) {
AnnotationDataImpl annotAtPoint =
new AnnotationDataImpl(setHandler.set, ann);
//add annotations to edit to the popup menu
popup.add(new HighlightMenuItem(
new EditAnnotationAction(annotAtPoint),
annotAtPoint.getAnnotation().getStartNode().getOffset().intValue(),
annotAtPoint.getAnnotation().getEndNode().getOffset().intValue(),
popup));
}
}
}
if (popup.getComponentCount() == 0) {
// nothing to do
} else if(popup.getComponentCount() == 1
|| (popup.getComponentCount() == 2
&& popup.getComponent(1) instanceof JSeparator)) {
//only one annotation, start the editing directly
//or only one selection, add new annotation
((JMenuItem)popup.getComponent(0)).getAction().actionPerformed(evt);
} else { //mouse hover a selection AND annotation(s)
try{
Rectangle rect = textPane.modelToView(textLocation);
//display the popup
popup.show(textPane, rect.x + 10, rect.y);
}catch(BadLocationException ble){
throw new GateRuntimeException(ble);
}
}
}
示例13: createPopupMenu
import javax.swing.JPopupMenu; //导入方法依赖的package包/类
/**
* Creates a popup menu for the panel.
*
* @param properties include a menu item for the chart property editor.
* @param save include a menu item for saving the chart.
* @param print include a menu item for printing the chart.
* @param zoom include menu items for zooming.
*
* @return The popup menu.
*/
protected JPopupMenu createPopupMenu(boolean properties,
boolean save,
boolean print,
boolean zoom) {
JPopupMenu result = super.createPopupMenu(properties, save, print, zoom);
int zoomInIndex = getPopupMenuItem(result, "Zoom In");
int zoomOutIndex = getPopupMenuItem(result, "Zoom Out");
int autoIndex = getPopupMenuItem(result, "Auto Range");
if (zoom) {
JMenuItem zoomIn = new JMenuItem("Zoom In");
zoomIn.setActionCommand(POLAR_ZOOM_IN_ACTION_COMMAND);
zoomIn.addActionListener(this);
JMenuItem zoomOut = new JMenuItem("Zoom Out");
zoomOut.setActionCommand(POLAR_ZOOM_OUT_ACTION_COMMAND);
zoomOut.addActionListener(this);
JMenuItem auto = new JMenuItem("Auto Range");
auto.setActionCommand(POLAR_AUTO_RANGE_ACTION_COMMAND);
auto.addActionListener(this);
if (zoomInIndex != -1) {
result.remove(zoomInIndex);
}
else {
zoomInIndex = result.getComponentCount() - 1;
}
result.add(zoomIn, zoomInIndex);
if (zoomOutIndex != -1) {
result.remove(zoomOutIndex);
}
else {
zoomOutIndex = zoomInIndex + 1;
}
result.add(zoomOut, zoomOutIndex);
if (autoIndex != -1) {
result.remove(autoIndex);
}
else {
autoIndex = zoomOutIndex + 1;
}
result.add(auto, autoIndex);
}
return result;
}