I am researching possibility of testing Java GUI application with Jemmy library.

Elements in application are defined by constructors like:

JFrameOperator mainFrame = new JFrameOperator("Main window title");
JButtonOperator flsButton = new JButtonOperator(mainFrame, "Button name");

Possible constructors are (depends on element, but here is the common set):

JSomeComponentOperator(ContainerOperator cont)
JSomeComponentOperator(ContainerOperator cont, int index)
JSomeComponentOperator(ContainerOperator cont, String title)
JSomeComponentOperator(ContainerOperator cont, String title, int index)

JSomeComponentOperator(ContainerOperator cont, ComponentChooser chooser)
JSomeComponentOperator(ContainerOperator cont, ComponentChooser chooser, int index)

The first four constructors are easy to use: you should specify:

  • cont - container of the new object (parent object)
  • title - text on the object
  • index - index of element on the page (e.g. index counted through all JButtons)

But I could not find any reference on usage of ComponentChooser chooser.

Can anyone give some example on its usage?

Here is the dump of a button I'd like to define this way (e.g. by using tooltip text cause it is unique):

<component operator="org.netbeans.jemmy.operators.JButtonOperator">
    <property name="Class" value="javax.swing.JButton"/>
    <property name="Default button" value="false"/>
    <property name="Height" value="39"/>
    <property name="Showing" value="true"/>
    <property name="Tooltip text" value="Accounts"/>
    <property name="Visible" value="true"/>
    <property name="Width" value="39"/>
    <property name="X" value="1"/>
    <property name="Y" value="1"/>
    <property name="toString" value="javax.swing.JButton[,1,1,39x39,alignmentX=0.0,alignmentY=0.5,border=com.sun.java.swing.plaf.windows.XPStyle$XPEmptyBorder@554712c3,flags=296,maximumSize=,minimumSize=,preferredSize=,defaultIcon=jar:file:/C:/asu_eirc/59.1.4/icons.jar!/icons/32/abacus.gif,disabledIcon=sun.swing.ImageIconUIResource@2fc53144,disabledSelectedIcon=,margin=javax.swing.plaf.InsetsUIResource[top=2,left=14,bottom=2,right=14],paintBorder=true,paintFocus=true,pressedIcon=,rolloverEnabled=true,rolloverIcon=,rolloverSelectedIcon=,selectedIcon=,text=null,defaultCapable=false]"/>

1 Answer 1


Here is my example of ComponentChooser usage:

JButtonOperator flsButton = new JButtonOperator(mainFrame, new ComponentChooser() {
                public boolean checkComponent(Component comp) {
                    if (comp == null)
                        return false;
                    else if (!(comp instanceof JButton))
                        return false;
                    else if (((JButton)comp).getToolTipText().equals("Accounts"))
                        return true;
                        return false;

                public String getDescription() {
                    return "searching for JButton instance with ToolTipText='Accounts'";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.