154
155 /**
156 * We should post ITEM_STATE_CHANGED event when the same element is
157 * reselected.
158 */
159 @Override
160 public void setSelectedItem(final Object anObject) {
161 final Object oldSelection = selectedItemReminder;
162 if (oldSelection != null && oldSelection.equals(anObject)) {
163 selectedItemChanged();
164 }
165 super.setSelectedItem(anObject);
166 }
167
168 @Override
169 public void firePopupMenuWillBecomeVisible() {
170 super.firePopupMenuWillBecomeVisible();
171 SwingUtilities.invokeLater(() -> {
172 JPopupMenu popupMenu = getPopupMenu();
173 // Need to override the invoker for proper grab handling
174 if (popupMenu != null && popupMenu.getInvoker() != getTarget()) {
175 // The popup is now visible with correct location
176 // Save it and restore after toggling visibility and changing invoker
177 Point loc = popupMenu.getLocationOnScreen();
178 SwingUtilities.convertPointFromScreen(loc, this);
179 popupMenu.setVisible(false);
180 popupMenu.show(getTarget(), loc.x, loc.y);
181 }
182 });
183 }
184
185 private JPopupMenu getPopupMenu() {
186 for (int i = 0; i < getAccessibleContext().getAccessibleChildrenCount(); i++) {
187 Accessible child = getAccessibleContext().getAccessibleChild(i);
188 if (child instanceof JPopupMenu) {
189 return (JPopupMenu) child;
190 }
191 }
192 return null;
193 }
194 }
|
154
155 /**
156 * We should post ITEM_STATE_CHANGED event when the same element is
157 * reselected.
158 */
159 @Override
160 public void setSelectedItem(final Object anObject) {
161 final Object oldSelection = selectedItemReminder;
162 if (oldSelection != null && oldSelection.equals(anObject)) {
163 selectedItemChanged();
164 }
165 super.setSelectedItem(anObject);
166 }
167
168 @Override
169 public void firePopupMenuWillBecomeVisible() {
170 super.firePopupMenuWillBecomeVisible();
171 SwingUtilities.invokeLater(() -> {
172 JPopupMenu popupMenu = getPopupMenu();
173 // Need to override the invoker for proper grab handling
174 if (popupMenu != null
175 && popupMenu.isShowing()
176 && popupMenu.getInvoker() != getTarget()) {
177 // The popup is now visible with correct location
178 // Save it and restore after toggling visibility and changing invoker
179 Point loc = popupMenu.getLocationOnScreen();
180 SwingUtilities.convertPointFromScreen(loc, this);
181 popupMenu.setVisible(false);
182 popupMenu.show(getTarget(), loc.x, loc.y);
183 }
184 });
185 }
186
187 private JPopupMenu getPopupMenu() {
188 for (int i = 0; i < getAccessibleContext().getAccessibleChildrenCount(); i++) {
189 Accessible child = getAccessibleContext().getAccessibleChild(i);
190 if (child instanceof JPopupMenu) {
191 return (JPopupMenu) child;
192 }
193 }
194 return null;
195 }
196 }
|