August 2008 Archives

After playing around with the modification I made im my previous post to MediaView, I was able to come up with a solution that works for any Node you pass in. The class is called FXContainer. Its purpose it to scale its contents to whatever width & height you specify, while maintaining the aspect ratio of the original.

By default, this results in the "black bar" effect that you've probably seen used to maintain aspect ratio in movies. That is usually appropriate, but there are also times when you may want the content expanded to fit the FXContainer, while still respecting the aspect ratio. For example, you may want a background image to fill the entire frame, but not become distorted. That is what the fillDimensions attribute does.

Here are screenshots demonstating the FXContainer:
fillFalse.png fillTrue.png
Here is the source code.
You can run the demo via webstart below. I have pack200 enabled, which will greatly reduce the download size for those of you using the Java 1.6.10 beta.

Since the JavaFX Preview SDK was released, I have been toying around with its video support. Overall, it is really, really good. I'm impressed and I've only hit the tip of the iceberg. Of course, there is room for improvement. For example, the current MediaView class does not have any concept of width nor height, whereas the ImageView class does. I was able to fix that with this amazingly short piece of code.
Yes, that is really it. To use it, just swap out ImprovedMediaView for MediaView, and set your width, height, and fill like this...
The result looks like this:
imv-cap1.png
imv-cap2.png

About this Archive

This page is an archive of entries from August 2008 listed from newest to oldest.

July 2008 is the previous archive.

Find recent content on the main index or look in the archives to find all content.

Pages

Powered by Movable Type 4.2-en