cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • DownloadSemiconductor Toolkit: Tools to create wafer maps, add wafer geometry to graphics, explore die defects & compare wafers.
  • Discovery Summit 2026: Early User Edition - September 23-24.Register. It's free.
  • Use JMP Clinical with CDISC-compliant data. Review studies, ID safety and efficacy signals & communicate findings with interactive graphics. Register to see how. Aug. 27, 2 pm US ET.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
EOwl
Level III

How to stretch a picturebox to a window while maintaining an aspect ratio?

I'm writing a script that will generate a GUI for displaying images, using a rowstate handler to pass the images over to the window.

Is there a way to set a picture box object to:

  1. Stretch with window size (with a minimum and maximum size defined)
  2. Maintain it's original aspect ratio (e.g. square) (see script 2)
  3. Forbid direct user re-sizing.

Here's some JSL that uses the sample table of images.

Clear Globals();
Names Default To Here(1);

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

//Set the picture equal to selected row
rs_updateviewer = Expr(
	
	SelectedRows = (dt << Get Selected Rows());
	i = If(N Items(SelectedRows) == 0, 1, SelectedRows[1]);
	
	img = column(dt, "pet")[i];
	pb << Set Image(img);
);

//Viewer Window
Viewer = New Window(
	"Viewer",
	Show Menu( 0 ),
	<< On Close(Clear Globals(rs);
	),
	<< Size Window( 1000, 700),
	
	vb = V List Box("Center",
	H Center Box( Text Box( "Viewer" ) ),
	H List Box(
//	tb = dt << New Data Box(),
	tb = Data Grid Box(),
	pb = Picture Box()
	)
	)
	,
	pb << Set Stretch( "Fill", "Fill" );
	pb << Border( 1 );
	
	tb << Set Stretch( "Off", "Off" );
	tb << Set Data Table( dt );
	tb << Close Side Panels( 1 );
	
);

//Initiate image
rs_updateviewer;

// Define the handler function
f = Function( {a},
	rs_updateviewer
);

// Register the row state handler to the table
set_rowstate = Expr(
	rs = dt << Make Row State Handler( f );
);

set_rowstate;

Here's an script index example of a graph with it's aspect ratio fixed, the behaviour I'd like on the picture

Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = Graph Builder( Show Control Panel( 0 ), Variables( X( :height ), Y( :weight ) ), Elements( Points( X, Y ), Smoother( X, Y ) ) );
gb << Fit to Window( "Maintain Aspect Ratio" );
3 REPLIES 3
jthi
Super User

Re: How to stretch a picturebox to a window while maintaining an aspect ratio?

Which min/max size has been determined (window or picture)? Should user be allowed to resize the window but not the picture? And is allowed to resize the window, should picture be able to resize to this new window size?

-Jarmo
EOwl
Level III

Re: How to stretch a picturebox to a window while maintaining an aspect ratio?

Lets use min/max sizes of 100x100 to 800x800 on the picture, 200x300 to 1000x900 for the window.

User can resize the window, not the picture (directly).

Picture grows and shrinks with window size, maintaining it's square aspect ratio. That means there'll be some empty space if the window is short and wide or tall and thin.

jthi
Super User

Re: How to stretch a picturebox to a window while maintaining an aspect ratio?

I don't think you can have min/max size for the window; you can only set the initial size.

I think it might be easiest to Graph Builder and fill it with the picture as it can maintain the aspect ratio but I'm not sure how to set min/max size without testing it out. Other option could be to utilize graphic script to resize display elements as graphic script will re-trigger when window size changes.

-Jarmo

Recommended Articles