Subscribe Bookmark RSS Feed

Capturing mouse clicks on non Graph objects with JSL

javier_guzman0

Community Trekker

Joined:

Sep 18, 2015

I have been reading a lot on the mousetrap() and handle() functions, but these seem to be reserved for Graph Box objects. I was wondering If I could add a "On click" event to any graphical element in a window? For example, in the following code:

    GuiWindow = NewWindow("SMS1");

    theBox = TableBox(

    stringColBox("State",{"Florida", "Texas", "Main", "California"}),

    NumberColBox("Width",{45,66,88,13}),

    NumberColBox("Length",{67,34,1,78}),

    NumberColBox("Depth",{13,65,32,56}));

    GuiWindow << Append(theBox);

Can I add a mouse trap or similar 'on click' behavior to a table box? So if the user where to click on anywhere inthe table, can it do something like Write("Hello World"); ?

2 REPLIES
pmroz

Super User

Joined:

Jun 23, 2011

For a tablebox you can make it selectable and add a row change function.  See the example below.

dt = Open( "$SAMPLE_DATA/Big Class.jmp" );

Summarize( a = by( age ), c = count, sumHt = Sum( Height ),

    meanHt = Mean( Height ), minHt = Min( Height ),

    maxHt = Max( Height )

);

sr = New Window( "Summary Results",

    tb = Table Box(

        String Col Box( "Age", a ),

        Number Col Box( "Count", c ),

        Number Col Box( "Sum", sumHt ),

        Plot Col Box( "Sum", sumHt),

        Number Col Box( "Mean", meanHt ),

        Number Col Box( "Min", minHt ),

        Number Col Box( "Max", maxHt )

    )

);

tb << set shade alternate rows(1) << set row borders(1) << set column borders(1);

tb << Set Selectable Rows(1);

tb << set row change function(

    Function( {this},

row_list = this << get selected rows;

        if (nrows(row_list) > 0,

one_row = row_list[1];

            print("Row selected: " || char(one_row));

        );

    );

);

msharp

Super User

Joined:

Jul 28, 2015

What you want is the mouse box function.

GuiWindow = NewWindow("SMS1");

theBox = TableBox(

    stringColBox("State",{"Florida", "Texas", "Main", "California"}),

    NumberColBox("Width",{45,66,88,13}),

    NumberColBox("Length",{67,34,1,78}),

    NumberColBox("Depth",{13,65,32,56}));

GuiWindow << Append(Mousebox(theBox,

  <<SetClickEnable(1),

  <<SetClick(function({this,clickpt,event},

  if(event == "Pressed",

  write("Hello World"))

  ))

));