下面列出了javax.swing.JPopupMenu#pack ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void doSelect(JComponent owner) {
invokingComponent = owner;
invokingComponent.addMouseListener(this);
invokingComponent.addMouseMotionListener(this);
pTable.addMouseListener(this);
pTable.addMouseMotionListener(this);
pTable.getSelectionModel().addListSelectionListener( this );
displayer.getModel().addComplexListDataListener( this );
Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
popup = new JPopupMenu();
popup.setBorderPainted( false );
popup.setBorder( BorderFactory.createEmptyBorder() );
popup.add( pTable );
popup.pack();
int locationX = x - (int) pTable.getPreferredSize().getWidth();
int locationY = y + 1;
popup.setLocation( locationX, locationY );
popup.setInvoker( invokingComponent );
popup.addPopupMenuListener( this );
popup.setVisible( true );
shown = true;
invocationTime = System.currentTimeMillis();
}
private void doSelect(JComponent owner) {
invokingComponent = owner;
invokingComponent.addMouseListener(this);
invokingComponent.addMouseMotionListener(this);
pTable.addMouseListener(this);
pTable.addMouseMotionListener(this);
pTable.getSelectionModel().addListSelectionListener( this );
controller.getTabModel().addComplexListDataListener( this );
Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
popup = new JPopupMenu();
popup.setBorderPainted( false );
popup.setBorder( BorderFactory.createEmptyBorder() );
popup.add( pTable );
popup.pack();
int locationX = x - (int) pTable.getPreferredSize().getWidth();
int locationY = y + 1;
popup.setLocation( locationX, locationY );
popup.setInvoker( invokingComponent );
popup.addPopupMenuListener( this );
popup.setVisible( true );
shown = true;
invocationTime = System.currentTimeMillis();
}
public void showDialpad(Component comp, boolean rightAligned) {
menu = new JPopupMenu();
menu.setFocusable(false);
menu.add(this);
menu.pack();
if (rightAligned) {
int width = (int)menu.getPreferredSize().getWidth();
menu.show(comp, -width + comp.getWidth(), comp.getHeight());
}
else {
menu.show(comp, 0, comp.getHeight());
}
this.requestFocus();
}
/** Mysterious calls to pack(), invalidate() and validate() ;-) */
private static void refreshPopup(JPopupMenu popup) {
popup.pack();
popup.invalidate();
Component c = popup.getParent();
if (c != null) {
c.validate();
}
}
void refreshMenu() {
JPopupMenu popupMenu = getPopupMenu();
popupMenu.pack();
popupMenu.invalidate();
popupMenu.revalidate();
popupMenu.repaint();
}
/** Gets popup menu. Overrides superclass. Adds lazy menu items creation. */
public JPopupMenu getPopupMenu() {
JPopupMenu pm = super.getPopupMenu();
pm.removeAll();
pm.add(new AddNavigationRuleAction());
pm.add(new AddNavigationCaseAction());
pm.add(new JSeparator());
pm.add(new AddManagedBeanAction());
pm.pack();
return pm;
}
/** Gets popup menu. Overrides superclass. Adds lazy menu items creation. */
public JPopupMenu getPopupMenu() {
JPopupMenu pm = super.getPopupMenu();
pm.removeAll();
pm.add(new AddActionAction());
pm.add(new AddForwardInlcudeAction());
pm.add(new AddForwardAction());
pm.add(new AddExceptionAction());
pm.add(new JSeparator());
pm.add(new AddFormBeanAction());
pm.add(new AddFormPropertyAction());
pm.pack();
return pm;
}
public void showDialpad(TelephoneTextField callField) {
menu = new JPopupMenu();
menu.setFocusable(false);
menu.add(this);
menu.pack();
this.callField = callField;
menu.show(callField, 0, callField.getHeight());
}
public @Override JPopupMenu getPopupMenu(){
JPopupMenu pm = super.getPopupMenu();
pm.removeAll();
boolean enable = false;
BaseKit bKit = getKit();
if (bKit==null) bKit = BaseKit.getKit(NbEditorKit.class);
if (bKit!=null){
Action action = bKit.getActionByName(NbEditorKit.generateFoldPopupAction);
if (action instanceof BaseAction) {
JTextComponent component = NbCodeFoldingAction.getComponent();
MimePath mimePath = component == null ? MimePath.EMPTY : MimePath.parse(DocumentUtilities.getMimeType(component));
Preferences prefs = MimeLookup.getLookup(mimePath).lookup(Preferences.class);
boolean foldingAvailable = prefs.getBoolean(SimpleValueNames.CODE_FOLDING_ENABLE, EditorPreferencesDefaults.defaultCodeFoldingEnable);
if (foldingAvailable){
ActionMap contextActionmap = org.openide.util.Utilities.actionsGlobalContext().lookup(ActionMap.class);
if (contextActionmap!=null){
foldingAvailable = contextActionmap.get(BaseKit.collapseFoldAction) != null &&
component != null;
if (!foldingAvailable){
bKit = BaseKit.getKit(NbEditorKit.class);
if (bKit!=null){
Action defaultAction = bKit.getActionByName(NbEditorKit.generateFoldPopupAction);
if (defaultAction instanceof BaseAction) action = defaultAction;
}
}
}
}
JMenu menu = (JMenu)((BaseAction)action).getPopupMenuItem(foldingAvailable ? component : null);
if (menu!=null){
Component comps[] = menu.getMenuComponents();
for (int i=0; i<comps.length; i++){
pm.add(comps[i]);
if (comps[i].isEnabled() && !(comps[i] instanceof JSeparator)) {
enable = true;
}
}
}
}
}
setEnabled(enable);
pm.pack();
return pm;
}