下面列出了javax.swing.event.PopupMenuEvent#getSource() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
JPopupMenu popup = (JPopupMenu) e.getSource();
popup.removeAll();
popup.setInvoker(null);
// hack
KeyStroke esc = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
JComponent c = getOutputPane().getTextView();
c.getInputMap().put(esc, handle);
getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(esc, handle);
//hack end
popup.removePopupMenuListener(this);
for (TabAction action : popupItems) {
action.clearListeners();
}
}
/**
* Alter the bounds of the popup just before it is made visible.
*/
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
@SuppressWarnings("unchecked")
JComboBox<E> comboBox = (JComboBox<E>) e.getSource();
if (comboBox.getItemCount() == 0) return;
final Object child = comboBox.getAccessibleContext().getAccessibleChild(0);
if (child instanceof BasicComboPopup) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
customizePopup((BasicComboPopup) child);
}
});
}
}
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
JComboBox box = (JComboBox) e.getSource();
Object comp = box.getUI().getAccessibleChild(box, 0);
if (!(comp instanceof JPopupMenu)) {
return;
}
JComponent scrollPane = (JComponent) ((JPopupMenu) comp).getComponent(0);
Dimension size = new Dimension();
size.width = scrollPane.getPreferredSize().width;
final int boxItemCount = box.getModel().getSize();
for (int i = 0; i < boxItemCount; i++) {
final JLabel label = new JLabel();
Object elementAt = box.getModel().getElementAt(i);
if (elementAt != null && elementAt instanceof Product) {
label.setText(((Product) elementAt).getDisplayName());
}
size.width = Math.max(label.getPreferredSize().width, size.width);
}
size.height = scrollPane.getPreferredSize().height;
scrollPane.setPreferredSize(size);
scrollPane.setMaximumSize(size);
}
/**
* Alter the bounds of the popup just before it is made visible.
*
* @param e The event.
*/
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
JComboBox<?> comboBox = (JComboBox) e.getSource();
if (comboBox.getItemCount() == 0) {
return;
}
final Object child = comboBox.getAccessibleContext().getAccessibleChild(0);
if (child instanceof BasicComboPopup) {
SwingUtilities.invokeLater(() -> customizePopup((BasicComboPopup) child));
}
}
@Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
if (!menuInitialized) {
JPopupMenu menu = (JPopupMenu)e.getSource();
debugHistorySupport.init(menu);
attachHistorySupport.init(menu);
menuInitialized = true;
} else {
debugHistorySupport.refreshItems();
}
}
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
// if the combo box does not contain a prototype display value, skip our sizing logic
final Object prototypeValue = comboBox.getPrototypeDisplayValue();
if (prototypeValue == null) return;
final JComponent popupComponent = (JComponent) e.getSource();
// attempt to extract the JScrollPane that scrolls the popup
if (popupComponent.getComponent(0) instanceof JScrollPane) {
final JScrollPane scroller = (JScrollPane) popupComponent.getComponent(0);
// fetch the existing preferred size of the scroller, and we'll check if it is large enough
final Dimension scrollerSize = scroller.getPreferredSize();
// calculates the preferred size of the renderer's component for the prototype value
final Dimension prototypeSize = getPrototypeSize(prototypeValue);
// add to the preferred width, the width of the vertical scrollbar, when it is visible
prototypeSize.width += scroller.getVerticalScrollBar().getPreferredSize().width;
// adjust the preferred width of the scroller, if necessary
if (prototypeSize.width > scrollerSize.width) {
scrollerSize.width = prototypeSize.width;
// set the new size of the scroller
scroller.setMaximumSize(scrollerSize);
scroller.setPreferredSize(scrollerSize);
scroller.setMinimumSize(scrollerSize);
}
}
}
@Override
public void popupMenuWillBecomeInvisible(final PopupMenuEvent e) {
lastPopupCloseTime = System.currentTimeMillis();
JPopupMenu jPopupMenu = (JPopupMenu) e.getSource();
jPopupMenu.removePopupMenuListener(this);
for (PopupMenuListener otherListener : otherListeners) {
jPopupMenu.removePopupMenuListener(otherListener);
}
}
@Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
JComboBox<?> combo = (JComboBox<?>) e.getSource();
Dimension size = combo.getSize();
if (size.width >= POPUP_MIN_WIDTH) {
return;
}
if (!adjusting) {
adjusting = true;
combo.setSize(POPUP_MIN_WIDTH, size.height);
combo.showPopup();
}
combo.setSize(size);
adjusting = false;
}
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
JComboBox combo = (JComboBox) e.getSource();
confirm(new EventObject(combo.getEditor().getEditorComponent()));
combo.removePopupMenuListener(this);
}
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
JComboBox combo = (JComboBox) e.getSource();
confirm(new EventObject(combo.getEditor().getEditorComponent()));
combo.removePopupMenuListener(this);
}
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
JComboBox combo = (JComboBox) e.getSource();
confirm(new EventObject(combo.getEditor().getEditorComponent()));
combo.removePopupMenuListener(this);
}
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
JComboBox combo = (JComboBox) e.getSource();
confirm(new EventObject(combo.getEditor().getEditorComponent()));
combo.removePopupMenuListener(this);
}
@Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
JComboBox<?> c = (JComboBox<?>) e.getSource();
c.setSelectedItem(c.getEditor().getItem());
}
@Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
JComboBox<?> c = (JComboBox<?>) e.getSource();
c.setSelectedItem(c.getEditor().getItem());
}
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
final JComponent popupComponent = (JComponent) e.getSource();
fixPopupLocation(popupComponent);
}