Calling fitTransformerToContents does not always work

Article ID: 2137
Last updated: 29 May, 2018
Article ID: 2137
Last updated: 29 May, 2018
Revision: 3
Views: 629
Posted: 06 Jan, 2010
by Dean J.
Updated: 29 May, 2018
by Gargani A.

Question

Why calling fitTransformerToContent does not work?

Answer

Two different problems may occur when you call fitTransformerToContent() or fitToContents(), or when you use the toolbar button 'fit to contents.'

  • You have to call the method many times to achieve the correct transformation.

This behavior occurs when you use a logical zoom or a mixed zoom.
In such contexts, the objects have a fixed size and it takes longer to find the correct transformer so that the objects fit the view. In the JViews method fitTransformerToContent (which is called within JViews TGO), an iteration is already performed to make sure that the transformer has a stable value. However, it may not be sufficient, which is why you have to call this method several times.

If you call fitTransformerToContent() several times to get a better result, it may take a while, as you have to do it more than once. If you have a fixed number of objects and a fixed size of window, you may foresee the number of calls to this method. This way, you can have your own method call fitToContents several times.

There is a workaround to this problem: You can use the method fitToContents which takes an Insets as parameter instead: fitToContents(java.awt.Insets);

This method can be called on instances of IlpNetworkView or IlvManagerView. Here is an example:
fitToContents(new Insets(5, 5, 5, 5));
or, if this is not enough:
fitToContents(new Insets(10, 10, 10, 10));

  • The transformer is not applied and nothing seems to happen.

This occurs when fitTransformerToContent() is called before having a visible view.
In this case, it is normal to get such a behavior.
Before the view is displayed, its size is null. Therefore the call to fitTransformerToContent() has no effect. You must make sure that your view has a size defined, in order to see the effect of the method fitTransformerToContent().

If you call

  setVisible();

fitTransformerToContent();

in this order, you will probably not see the effect of the method fitTransformerToContent().
In fact, the method setVisible(), which sets the size of the view, is an asynchronous method. This means that the method fitTransformerToContent() can be called before setVisible() actions are performed.

To make sure that the method fitTransformerToContent() is not called too early, you can use the method SwingUtilities.invokeLater(...) with the method fitTransformerToContent() as parameter, just after calling setVisible().

Example:

   SwingUtilities.invokeLater(
new Runnable() { public void run () { fitTransformerToContent(); } });

You can find more information about threads on the SUN web site at the following URLs:

This article was:   Helpful | Not helpful
Report an issue
Article ID: 2137
Last updated: 29 May, 2018
Revision: 3
Views: 629
Posted: 06 Jan, 2010 by Dean J.
Updated: 29 May, 2018 by Gargani A.
Also listed in


Others in this category