swinglibrary: can't get treenode popup to work

120 views
Skip to first unread message

Bill Schoolfield

unread,
Apr 26, 2011, 2:51:39 PM4/26/11
to robotframework-users
Hello,

In my java app, users can right click on a tree node to get a popup
menu. I'm trying to replicate this. I can get the
node selected. But the keywords that handle the popup and menu
selection fail.

I have tried using:

"Select Tree Node" followed by "Select From Popup Menu On Selected
Tree Nodes"

"Select From Tree Node Popup Menu"

"Select From Tree Node Popup Menu In Separate Thread"

All to no avail. Pretty sure the component selection is correct.

TIA for you help.

Bill

bschooly

unread,
Apr 27, 2011, 1:01:44 AM4/27/11
to robotframework-users
Recreated problem with small test:

package simplejtreeexample;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;

public class SimpleJTreeExample extends JFrame {

JPopupMenu treeMenu;

public static void main(String[] argv) {
SimpleJTreeExample myExample = new SimpleJTreeExample("Simple
JTree Example");
}

public SimpleJTreeExample(String title) {
super(title);
setSize(150, 150);
addWindowListener(new WindowAdapter() {

@Override
public void windowClosing(WindowEvent we) {
dispose();
System.exit(0);
}
});
init();
pack();
setVisible(true);
}

private void init() {
final JTree jt = new JTree();
jt.setName("myTree");
jt.addMouseListener(new MouseAdapter() {

@Override
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger() && e.getClickCount() == 1) {
doPopup(e.getX(), e.getY());
}
}

public void doPopup(int x, int y) {
if (treeMenu == null) {
treeMenu = new JPopupMenu();
JMenuItem newItem = new JMenuItem("New");
treeMenu.add(newItem);
}
treeMenu.show(jt, x, y);
}
});
JScrollPane js = new JScrollPane(jt);
getContentPane().add(js);
}
}

Test file is:

*** Settings ***
Library SwingLibrary
Suite Setup Start Test Application

*** Test Cases ***
Test do popup
List Components In Context
Select From Tree Node Popup Menu In Separate Thread myTree
colors New

*** Keywords ***
Start Test Application
Start Application simplejtreeexample.SimpleJTreeExample
Select Window Simple JTree Example

Results:

FAIL Popup menu

Any ideas? What am I doing wrong?????

Florian Heine

unread,
May 28, 2012, 10:51:18 AM5/28/12
to robotframe...@googlegroups.com
Hello Bill,

Did you ever find a solution to this problem? It sounds very similar to a problem I am currently having with popup menus on tree nodes.

I have searched high and low including in both the application and the swing library source code, but to no avail.

Any help will be definitely appreciated,


    Regards,
       Florian
Reply all
Reply to author
Forward
0 new messages