Win a copy of Programmers Guide to Apache Thrift this week in the Open Source forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

AffineTransform rarities  RSS feed

 
Saloon Keeper
Posts: 3250
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was using an AffineTransform in one of my panels, and I noticed something strange. I've written about this same strangeness a year or two ago, but I did not get any response, unfortunately.

The problem is that when you use an AffineTransform to enable using user coordinates, and you resize the panel, then the origin of the panel is that of the content pane, or something like that. I've written a short program that demonstrates the problem. The content pane has two panels, one at Page_Start, containing a button and a label, and a center panel that draws a red cross from two corners of that panel to the opposite corners. When the program starts, no use of an AffineTransform is made, and so everything seems normal. You can safely resize the frame. When the button is clicked, and the AffineTransform is set up (that transform is just the identity transform, so nothing different should happen), then at first all seems oke, that is: until the frame gets resized. Then you see that that cross seems to start from the content pane origin, or even from the frames corner.

If I am right, does anyone know what the cause of this behaviour is? Meanwhile, I'm investigating further. If I find out something, I will report it here.
 
Marshal
Posts: 64471
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe the problem has to do with this.getHeight() rather than panel.getHeight()?? Line 27.
 
Piet Souris
Saloon Keeper
Posts: 3250
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Campbell,

unfortunately,, that is not the problem. The "this" is really the panel in question. Yu can add this code snippet to the paintComponent method, to see the sizes:

 
Greenhorn
Posts: 5
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem is that you are not supposed to simply set the transform. You are supposed to apply your transform to the current transform.

If you print the transform before your call to set transform, you sill notice that it has a y offset. This is to move the origin of your panel past the
panel containing the button.  For me it is a 36 your mileage may vary. When you set this number to zero, as happens when you set the transform to the identity transform, zero zero moves up to the user left corner of the JFrame.
 
Piet Souris
Saloon Keeper
Posts: 3250
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Jack,

absolutely spot on! Never knew this. Thanks and have a cow!

(as Jack advised: I changed 'g2d.setTransform' to 'g2d.transform')


Edit: by the way: it also cured the problem that when dragging the frame off and on the screen, the DoubleBuffering is sti;ll working as normal. With my initial transform, weird things happened!
 
Jack Marsh
Greenhorn
Posts: 5
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the Cow; I'm glad I could be of help.  Next time, please include the imports. I decided to do it bare bones no IDE ( probably a false economy of time ).
 
Piet Souris
Saloon Keeper
Posts: 3250
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry! Mea culpa.

Since IDE's fix the imports for you at the click of a mouse button, I always leave them out, saves a lot of space. Next time I'll put them in again
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!