APS Excellence in Physics Education Award
November 2019

Education Prize Logo
Science SPORE Prize
November 2011

NSF Logo
The Open Source Physics Project is supported by NSF DUE-0442581.

Screenshot Dialog post and replies

Return to the Screenshot Dialog thread
Login to post to this thread

Screenshot Dialog
Julia Branke
11 Posts

In an ejs Simulation you can take a screenshot with right mouse click, screenshot (third from above in menue, not sure about what is really says in English) and then image.

My problem is (on OS X) that the dialog does not fit into the window that shows and it looks weird, unless you resize the dialog, but this is sort of not really obvious, that something is hidden.

I think the image that will be saved is just not scaled right into the dialog.

I wanted to offer a button in my simulation to save a screenshot and would be happy to have a dialog without any image in it.

In Eclipse I achieved this by making a function like the function saveImage out of SnapshotTool and commented out some lines (see end of post).

But if I package the simulation out of eclipse I get way bigger file sizes than out of ejs, and I have not figured out how to change this (any hints on this would also be appreciated) and so I would like to have the dialog without picture or with correctly displayed picture in ejs. A _view.saveImage function would be great.

I gave up the put my saveImage Function into ejs, because of all the imports I would need to do so. But maybe I will try again using the imports functionality in run options.

But I still would like the screenshot dialog to look neat.

Any help would be greatly appreciated.

    if((output==null)&&(filename==null)) {                                 // Select target file and scale
      JLabel label = new JLabel();
      label.setIcon(new ImageIcon(bi));
      /* This code is temporarily disabled because it doesn't work properly for all types of components
//      JLabel labelScale = new JLabel(res.getString("SnapshotTool.Scale")); //$NON-NLS-1$
//      labelScale.setBorder(new javax.swing.border.EmptyBorder(0, 5, 0, 5));
      JTextField scaleField = new JTextField(Double.toString(scale));
//      JPanel scalePanel = new JPanel(new BorderLayout());
//      scalePanel.add(labelScale, BorderLayout.WEST);
//      scalePanel.add(scaleField, BorderLayout.CENTER);
//      JPanel panel = new JPanel(new BorderLayout());
//      panel.add(label, BorderLayout.CENTER);
//      panel.add(scalePanel, BorderLayout.SOUTH);

Attached File: dialog.png

Replies to Screenshot Dialog

Re: Screenshot Dialog -
Francisco Esquembre
232 Posts


There is a method of the view called

   * Saves the image produced by a component to disk.
   * @param _filename the name of a file (either in disk or in memory). Null if the user must select a name.
   * @param _element the name of the view element to get the image from
   * @return true if the file was correctly saved
  public boolean saveImage (String _filename, String _element);

You can invoke it as both _view.saveImage of _saveImage.
The syntax is:
_saveImage ("MyFilename.jpg","plottingFrame");

The "plottingFrame" String refers to an element in your view with that name.

Please, test this to see if it is what you need.


Re: Re: Screenshot Dialog -
Julia Branke
11 Posts

Dear Paco,

thank you so much, this is exactly what I needed!

_saveImage works for me

_view.saveImage does not (which explains, why I can not find if, if I look at the _view. functions offered in eclipse).

I will remember to look at the _functions in future.

Thank you,


OSP Projects:
Open Source Physics - EJS Modeling
Physlet Physics
Physlet Quantum Physics
STP Book