BookmarkSubscribeRSS Feed
javier_guzman0

Community Trekker

Joined:

Sep 18, 2015

Capturing mouse clicks on non Graph objects with JSL

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 = New Window( "SMS1" );
theBox = Table Box(
	String Col Box( "State", {"Florida", "Texas", "Main", "California"} ),
	Number Col Box( "Width", {45, 66, 88, 13} ),
	Number Col Box( "Length", {67, 34, 1, 78} ),
	Number Col Box( "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

Re: Capturing mouse clicks on non Graph objects with JSL

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

Re: Capturing mouse clicks on non Graph objects with JSL

What you want is the mouse box function.

 

GuiWindow = New Window( "SMS1" );
theBox = Table Box(
	String Col Box( "State", {"Florida", "Texas", "Main", "California"} ),
	Number Col Box( "Width", {45, 66, 88, 13} ),
	Number Col Box( "Length", {67, 34, 1, 78} ),
	Number Col Box( "Depth", {13, 65, 32, 56} )
);
GuiWindow << Append(
	MouseBox(
		theBox,
		<<SetClickEnable( 1 ),
		<<SetClick( Function( {this, clickpt, event}, If( event == "Pressed", Write( "Hello World" ) ) ) )
	)
);