Skip to content

Commit 8eec476

Browse files
committed
Fix context menu UX: show it on right-click no matter what was the selection
Previously popup menu was not shown if the tree node was not selected.
1 parent 1d04c27 commit 8eec476

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/core/src/main/java/org/apache/jmeter/gui/GuiPackage.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -633,10 +633,9 @@ public void displayPopUp(Component invoker, MouseEvent e, JPopupMenu popup) {
633633
if (popup != null) {
634634
log.debug("Showing pop up for {} at x,y = {},{}", invoker, e.getX(), e.getY());
635635

636-
popup.pack();
636+
// Enforce heavyweight popup to show shadows on macOS
637+
popup.setLightWeightPopupEnabled(false);
637638
popup.show(invoker, e.getX(), e.getY());
638-
popup.setVisible(true);
639-
popup.requestFocusInWindow();
640639
}
641640
}
642641

src/core/src/main/java/org/apache/jmeter/gui/tree/JMeterTreeListener.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import javax.swing.JPopupMenu;
2929
import javax.swing.JTree;
30+
import javax.swing.SwingUtilities;
3031
import javax.swing.event.TreeSelectionEvent;
3132
import javax.swing.event.TreeSelectionListener;
3233
import javax.swing.tree.TreePath;
@@ -154,7 +155,6 @@ public void mouseClicked(MouseEvent ev) {
154155

155156
@Override
156157
public void mouseReleased(MouseEvent e) {
157-
GuiPackage.getInstance().getMainFrame().repaint();
158158
}
159159

160160
@Override
@@ -234,6 +234,10 @@ private boolean isRightClick(MouseEvent e) {
234234

235235
private void displayPopUp(MouseEvent e) {
236236
JPopupMenu pop = getCurrentNode().createPopupMenu();
237-
GuiPackage.getInstance().displayPopUp(e, pop);
237+
// invokeLater ensures popup does not disappear when user right-clicks an inactive node
238+
// In other words: right-click different nodes and verify if menu is shown every time.
239+
// invokeLater seems to be required as long as tree.requestFocusInWindow(); is used
240+
// in valueChanged
241+
SwingUtilities.invokeLater(() -> GuiPackage.getInstance().displayPopUp(e, pop));
238242
}
239243
}

xdocs/changes.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ For instance, <code>While Contoller</code> is disabled in the following tree, so
8080
are gray. It is purely a UI change, and the behavior is not altered.
8181
</p>
8282
<figure width="223" height="256" image="changes/5.3/disabled_subtree.png">While controller is disabled, so its children are gray</figure>
83+
84+
<p>Tree context menu is shown even in case the node selection is changed. Previously
85+
the popup did disappear and it was required to select a node first and only then launch popup.</p>
8386
<!--
8487
<ch_title>Functions</ch_title>
8588
-->

0 commit comments

Comments
 (0)