Steve On Java

Hacking JavaFX and Java with Agility
  • rss
  • Home
  • About
  • Contact
  • SvJugFX
  • Prize Spinner

Launching Hyperlinks from JavaFX (including Mobile)

steveonjava | March 4, 2010

Creating hyperlinks in JavaFX should be in the category of things that are trivially easy, but is complicated by various factors, such as deployment mode and Java version. First I will go into detail on all the different permutations of how you can launch links in a browser and under what circumstances each will work. Next I will give you a nice packaged solution that you can use as a library (if you are impatient, just skip to The Easy Way Out now).  Finally, I will show how you can do the same thing for JavaFX Mobile applications.

A Tale of 3 APIs

There are 3 different ways that you can launch hyperlinks in Java/JavaFX. Unfortunately, none of them work in all circumstances, so you need to know when to call each. Here is a quick reference table:

AppletStageExtensionWeb Start BasicServiceDesktop.browse
Works in AppletYesYesYes
Works in Web StartNoYesYes
Works in ApplicationNoNoYes
Works on Java 1.5YesYesNo
Can Set TargetYesNoNo
Default Target_self_blank_self

AppletStageExtension

The first option is to use the JavaFX AppletStageExtension. This is only available if you are running as an Applet, but also gives you the most control over how the hyperlink is launched.  In addition to a URL you can also specify a target, which can be any of the standard HTML targets including the following (excerpted from the AppletStageExtension javadocs):

Target ArgumentDescription
"_self"Show in the window and frame that contain the applet.
"_parent"Show in the applet’s parent frame. If the applet’s frame has no parent frame, acts the same as “_self”.
"_top"Show in the top-level frame of the applet’s window. If the applet’s frame is the top-level frame, acts the same as “_self”.
"_blank"Show in a new, unnamed top-level window.
nameShow in the frame or window named name. If a target named name does not already exist, a new top-level window with the specified name is created, and the document is shown there.

Web Start BasicService

The second option is to use the Web Start BasicService.  This works from both JavaFX Applets and Web Start applications, but does not let you specify the HTML target.  It is effectively the same as using the AppletStageExtension with a target of “_blank”.

Here is a small code excerpt showing how you would call the Web Start BasicService from your JavaFX code:

def basicService = ServiceManager.lookup("javax.jnlp.BasicService") as BasicService;
basicService.showDocument(new URL(url));

Desktop.browse

The third option is to use the new Desktop class introduced in Java 1.6.  This works from Applet, Web Start applications, and Standard Execution (within a desktop Frame).  Unfortunately, it did not exist in Java 1.5, so it won’t work from JavaFX without a little hacking.

The quick and dirty hack is to modify your JavaFX distribution to include the rt.jar from Java 1.6 as explained in this earlier post.  The only problem with this is you also have to get all the other developers on your project to do the same (and redo this on every upgrade).

The friendlier approach is to use reflection to check and see if the Desktop class is available, and then invoke the methods dynamically.  There is quite a bit more boilerplate code, but it will allow you to compile with a plain vanilla JavaFX installation, and also handle the odd case where someone is trying to run JavaFX under 1.5.  (Which is unsupported on Windows/Unix, but happens to be the only option for the poor lost souls with 32 bit chips who have been abandoned by Apple).

Since the code is easier to follow without reflection, I will show that first:

Desktop.getDesktop().browse(new URI(url));

And here is the munged version with reflection:

try {
    def desktopClazz = Class.forName("java.awt.Desktop");
    def desktop = desktopClazz.getMethod("getDesktop").invoke(null);
    def browseMethod = desktopClazz.getMethod("browse", [URI.class] as java.lang.Class[]);
    browseMethod.invoke(desktop, new URI(url));
} catch (e) {
    println("Upgrade to Java 6 or later to launch hyperlinks: {url}");
}

The Easy Way Out

When things are easy to do, they will get done right.  To make sure that JavaFX applications do not fall prey to broken and inconsistent linking, I put together a library for JFXtras that takes care of all the plumbing for you.

There is a new JFXtras class called BrowserUtil that has a very simple API:

BrowserUtil.browse(url);

or

BrowserUtil.browse(url, target);

It is that simple…  Conversion of string URLs to URL or URI objects, selection of the correct API based on your deployment mode, and failover modes based on the Java version are all included.

In addition, I created an extended Hyperlink called the XHyperlink.  This behaves identically to the built-in control, with the addition of simple configuration of URL navigation (this is what hyperlinks are designed for, right?)  The usage of the XHyperlink class is as follows:

XHyperlink {
    text: "Oracle's Homepage", url: "http://oracle.com/"}
}

All of this functionality will be included in the JFXtras 0.6 release.  If you need it now, you can build off the head of our repo.  Otherwise we are working on a release, which I will announce on this blog shortly which you can follow.

What about JavaFX mobile?

None of these desktop techniques actually work on a mobile device, so this is not a 100% solution yet.

Fortunately, there is also a solution for JavaFX Mobile if you are willing to delve in to the Java ME APIs.  To do this you first need to get a handle to the MIDlet like this:

def midlet = com.sun.javafx.runtime.adapter.MIDletAdapter.getMidlet();

And then you can call platformRequest to launch a browser on the mobile device:

midlet.platformRequest(url);

Note: This requires use of private APIs, so this may not work in future JavaFX releases.

It is not possible to merge this in with the desktop solution, because the JavaFX Mobile libraries do not exist on the desktop platform (and vice versa), but it is relatively easy to use this technique yourself by copying and pasting the above code sample into a helper function in your application.

 
Comments
2 Comments »
Categories
JavaFX, JavaFX Mobile, jfxtras
Tags
hyperlinks, JavaFX, JavaFX Mobile, jfxtras
Comments rss Comments rss
Trackback Trackback

Hinkmond’s JavaFX Mobile Dojo

steveonjava | February 19, 2010

In case you missed the big event last week, I have finished post-processing and uploading the video.  We took the quality up a notch by getting a direct screen capture from the presenter laptop.  This means that you will not only get crystal clear slides, but also full-screen demos and a nice tight head-shot of the presenter.  This moves our video setup firmly up from a Level 4 to a premium Level 1 operation as detailed in Stephan Janssen’s blog.

Without further ado, here is the Parleys version of Hinkmond’s JavaFX Mobile Dojo talk:

I got a lot of requests for just the slides last time, so I am also making them available here:

Finally, a quick plug for our next SvJugFx event.  We will be doing a double feature with folks from the Java Store and JFrog Artifactory presenting back-to-back.  Even if you plan to attend online, make sure to sign-up here:
http://www.svjugfx.org/calendar/12559455/

 
Comments
5 Comments »
Categories
Events, JavaFX, SvJugFx
Tags
hinkmond wong, JavaFX, mobile, SvJugFx
Comments rss Comments rss
Trackback Trackback

JavaFX Layout Secrets with Amy Fowler

steveonjava | January 19, 2010

I finished post-processing and publishing our January talk with Amy Fowler on Parleys.com.

Here is a direct link: JavaFX Layout Secrets with Amy Fowler

I did my best to clean up the audio at the beginning to remove the static that our streaming listeners had to put up with. After the first 10 minutes we swapped mics, which made a huge difference!

Our plan for next month is to upgrade our streaming/recording setup once again so we can directly capture the presenter’s VGA signal for a dual-cast. This should allow us to capture the demos in full resolution and give a much better streaming experience. If you or your company is interested in helping sponsor some of our hardware needs, we can definitely use the help (contact me).

See you next month for Hinkmond’s JavaFX Mobile talk: Hinkmond’s JavaFX Mobile Dojo

 
Comments
No Comments »
Categories
Events, JavaFX, SvJugFx
Comments rss Comments rss
Trackback Trackback

JavaFX Layout Secrets

steveonjava | December 18, 2009

I am very pleased to have Amy Fowler (Aim) presenting on JavaFX Layouts at our January Silicon Valley JavaFX Users Group (SvJugFx).  For those of you who don’t know Aim, she was a founding member of the Swing team, has done some Rock Star presentations at JavaOne, and is a core member of the JavaFX team focused on all things layout.

If you are doing any JavaFX development at all, this is an event you won’t want to miss.  The presentation is on January 13th and you can sign-up on the SvJugFx website here:

Click to Sign-Up

We will also be streaming the event live from Santa Clara, so if you don’t live nearby make sure to join us online for the event.  I actually think the folks watching it online are at an advantage, because they get all the inside information in the chat window from JavaFX luminaries like Jim Weaver, Dean Iverson, and Jonathan Giles.

For those of you who missed our December event, we just finished posting Richard Bair’s December talk on JavaFX entitled “Intro to JavaFX – A Rich Client Platform for All Screens.”  You can view it on Parleys.com complete with synchronized slides by clicking on the image or link below:

Richard Bair Presenting on JavaFX at the SvJugFx

Click to View Presentation

I hope to see you at our next event!

 
Comments
4 Comments »
Categories
Events, JavaFX, SvJugFx, presentation
Tags
JavaFX, jug, SvJugFx
Comments rss Comments rss
Trackback Trackback

SvJugFx Streamed Live with Richard Bair

steveonjava | December 8, 2009

For those of you who don’t know, SvJugFx stands for the Silicon Valley JavaFX Users Group.  We will be holding our very first meeting this coming Wednesday with a live, streamed presentation from the world renowned Richard Bair (who is now infamous for divulging JavaFX secrets at Devoxx).

Richard Bair Presenting at Devoxx 2009

Yes, I said streamed live…  for those of you who are not fortunate enough to live in Silicon Valley, you can still participate in realtime by doing the following:

  1. Sign-up for the SvJugFx meetup group.  This is the primary communication vehicle we will use to announce last-minute changes:
    http://www.svjugfx.org/
    (Note: Everyone can sign up for the group, but please only RSVP for the event if you are physically attending)
  2. For the video feed, please go to the following ustream channel:

    http://www.ustream.tv/channel/silicon-valley-javafx-user-group

  3. And to participate, please log on to Google Moderator at the following URL:

    http://moderator.appspot.com/#16/e=d528e

The in-person meeting will start on: Wednesday at 6PM PST
The online streaming will start at latest by: 7PM PST (possibly earlier)

Please leave enough time to login on both sites and test your internet and video playback capabilities.  You will be able to watch the live video stream on ustream and respond with your own questions (as well as vote other participant’s questions up and down) via Google Moderator, which we will be monitoring during the presentation.

This is the first time we are trying this format, so we apologize in advance for technical glitches or issues that we are sure will arise.

“Success is the ability to go from failure to failure without losing your enthusiasm.”

–Winston Churchill

 
Comments
1 Comment »
Categories
Announcements, Events, JavaFX, SvJugFx, presentation
Tags
JavaFX, richard bair, SvJugFx
Comments rss Comments rss
Trackback Trackback

JFXtras 0.6 Preview Available!

steveonjava | November 25, 2009

Happy Thanksgiving from the JFXtras team!  While everyone else is celebrating the holiday with friends and family, we are going to be busy finishing up the 0.6 release.

Wild turkey in LaConner, WA taken by stevevoght

In case you have some spare time between meals and celebration, you can join in the fun too by trying out the JFXtras 0.6 preview release, which can be downloaded here:

http://code.google.com/p/jfxtras/downloads/list

There is a whole slew of new functionality including the following under Common:

  • Layouts – Changes to the Grid API in preparation for inclusion in the JavaFX Soma release, and also added animation support to all the layouts.
  • Sphere – Pseudo 3D sphere created for the Groovy showdown with Andrey Almiray.
  • Gear – New shape from Steve Bixby.
  • ManualResizableRectangle – Very useful shape from Yannick’s post.
  • JXScene – Pedro’s improved API for Swing integration.
  • PaintUtil, HSBColor, new gradients – Liu’s magic paint classes
  • Custom Paints – From Jeff Friesen’s excellent article on Custom Paints.
  • Custom Cursors – From Jeff Friesen’s excellent article on Custom Cursors.
  • Wipe Library – A transition library from Simon Morris’ JavaFX in Action book.
  • XMap – A bindable Map implementation for JavaFX.
  • XStore – David Armitage’s simple persistence for JavaFX variables using dependency injection.
  • ImageCache – Caching of JavaFX images for building high performance applications contributed by Joshua Marinacci.
  • XEDT – Simplified event thread mangement for JavaFX infrastructure classes (Warning: Use the JavaFX Task API instead unless you know exactly what you are doing)

And the rest under a new Controls jar:

  • XTableView – I am still working on this, but it is very useful already as demonstrated by Jim Weaver’s SpeedReaderFX application.
  • XTreeView – Jim Clarke’s Tree Control.
  • XCalendarPicker – Tom’s excellent calendar control.
  • XPane – A titled region with rounded corners developed by Dean Iverson.
  • XPicker – David Armitage did some great work on this…  Check out his demo on the JFXtras website.
  • XShelfView – A high performance Display Shelf control implementation with support for reflection, titles, and a scrollbar as showcased on JFXStudio.
  • XSpinnerWheel – A prize spinner wheel that makes use of pseudo 3D effects as showcased in the JUG Prize Spinner application.
  • XMenu – Pure JavaFX Menu developed by Jonathan Giles (this version will be replaced by the official Sun Menu control when it becomes available).
  • XPasswordBox – Control from Liu to create a password field.
  • XMultiLineTextBox – Till’s control for editing multiple lines of text.
  • XSwingTable – From John Freeman, this gives you all the power of a JTable directly from JavaFX code.

For this release we decided to go with a new naming convention to differentiate our classes from the built-in JavaFX layouts and controls.  Most of the classes are now prefixed with an “X” for jfXtras.  This will make migration slightly more painful now, but prevent future collisions and name changes down the road.

There is also a new version of JFXtras Test.  This is the final version that will be released under this name (it is being merged with FEST-JavaFX), but it required an update to work with the new naming convention and to add some much-needed JUnit Runner support (see my Devoxx Conference Presentation for more details).

I probably missed a few things along the way here.  You can find the definitive list in the online JavaFXDoc:

http://jfxtras.googlecode.com/svn/site/javadoc/release-0.6/index.html

Please feel free to download the jars and give the preview release a try.  We are putting the finishing touches on several of the layouts and controls, so expect a final release in a week or so.

Happy Thanksgiving!

 
Comments
16 Comments »
Categories
Announcements, JavaFX, jfxtras
Tags
controls, JavaFX, jfxtras, layouts
Comments rss Comments rss
Trackback Trackback

Devoxx Conference Session Slides

steveonjava | November 24, 2009

Overall I was very impressed with Devoxx.  Everything including the movie theater venue, quality of the speakers, and professionalism of the attendees was top-notch.  Stephan Janssen definitely puts on quite an amazing show!

As a follow-up to my second Devoxx session, here is the full slide deck I presented:

Both this and the university session will be available on the Parleys.com beta site shortly, so you will be able to watch both sessions from the comfort of your home.

Now back to coding on the JFXtras 0.6 release with an announcement to be posted here very shortly…

 
Comments
2 Comments »
Categories
JavaFX, jfxtras, presentation
Tags
devoxx, JavaFX, jfxtras
Comments rss Comments rss
Trackback Trackback

LearnFX and Win at Devoxx

steveonjava | November 13, 2009

Next week I will be giving two talks on JavaFX at Devoxx in Belgium.  The first is a university session on Tuesday at 13:30 called The JavaFX Platform – A Java Developer’s Guide.  The second is a technical session on Thursday at 14:00 entitled Pro Javafx – Developing Enterprise Applications.

Leading up to both these sessions I will post a question via the LearnFX application.  To win a prize, all you have to do is:

  1. Answer the question correctly using the LearnFX client (see below)
  2. Come to the next Devoxx session I am speaking at
  3. Winners will be selected by a random drawing from all the correct responses

Here is the LearnFX client displaying the first question.  To run it, make sure that you have a recent version (update 14 or later) of Java SE 6, and simply click on the launch button:

LearnFX
webstartsmall2

Please don’t ruin this for others by mentioning the answer!

The prizes include several copies of Pro JavaFX Platform and a limited edition WidgetFX T-Shirt.  I don’t know about you, but I know which prize I would pick:

WidgetFXShirt

WidgetFX Limited run T-Shirt - original artwork by Keith Combs (WidgetFX Developer)

There will also be an opportunity for audience members to answer simply by using a laptop or mobile Twitter client (more details on this at the start of the session), so you don’t have to respond in advance to win.

Thanks to Jim Weaver for the excellent LearnFX application, and I look forward to seeing you at my Devoxx talks!

 
Comments
1 Comment »
Categories
Events, JavaFX, contest
Tags
devoxx, learnfx, pro javafx
Comments rss Comments rss
Trackback Trackback

Announcing the JavaFX Twitter Group

steveonjava | November 7, 2009

JavaFX has a very active Twitter community.  Some have even said that the best way to get help with your JavaFX app is to ask on Twitter first.  But how do you know who to follow?

To make it easy to hook in to the JavaFX Twitter community, I put together a JavaFX Twitter Group using the new group support.  To subscribe, simply follow @steveonjava/javafx:

javafxgroup

The JavaFX Twitter Group Stream

So who will you find on this list?  Some big names in the JavaFX Community, including:

  • Richard Bair, Joshua Marinacci, and Jonathan Giles from the JavaFX team
  • JavaFX book authors such as Jim Weaver, Weiqi Gao, Dean Iverson, and Simon Morris
  • JavaFX evangelists such as Maijaliisa Burkert, and Anatoli Fomenko
  • JavaFX early adopters such as Peter Pilgrim, Sten Karl, Steven Herod, Carl Dea, William Antonio, Pär Dahlberg, Mark Macumber, Tom, Enrique Garcia, Eric Wendelin, Hideki Kobayashi, and many, many others

I tried my best to dig in a few levels deep on the twitter lists of folks I know are active in the JavaFX community so I would get pretty good coverage.  The basic criteria I used for selecting folks was percentage of tweets dedicated to JavaFX discussion.  Most of the folks on the list talk about JavaFX in 50% or more of their tweets, although there are a few notable exceptions (ahem..  Steven Herod).

Please follow the new JavaFX Twitter Group, and if you would like to be followed by the list, tweet me a direct message @steveonjava.

 
Comments
2 Comments »
Categories
Announcements, JavaFX
Tags
JavaFX, twitter, twitter group
Comments rss Comments rss
Trackback Trackback

Meet the New Java Store

steveonjava | November 4, 2009

The Java Store team at Sun has been busy at work on a new release of the Java Store, which is finally available in Beta.  The easiest way to get it is to go through the Java Warehouse to the developer preview link here:

http://store.java.com/developerrelease

(If you are on Windows 7 or Vista-64, you can still run the store with no problems…  Just make sure you have a 32-bit JRE installed)

The latest version of the Java Store sports a new look and feel that is a dramatic improvement over the early versions.  Some of the new user interface features include:

  • Integrated UI with Featured Apps, Top Downloads, and App Browsing all in one place
  • Free-form text search for finding new applications quickly
  • Improved navigation – New apps listed first, and navigation at all levels

JavaStoreBeta1

Perhaps the biggest change is the ability for developers to charge for applications.  This is provided via integration with PayPal, and currently available for U.S. customers.  Full details on the payment system can be found in this press release.

Of course, the best applications are available for free…  Be sure to try launching WidgetFX from the Java Store and let me know how it works!

JavaStoreBeta2

Congratulations to the JavaFX team on a very nice face lift for the Java Store!

I know that many of the Java Store development team members read this blog, including Joshua Marinacci, so feel free to use the comments section to give them constructive feedback.

(Did I mention Josh has an awesome new design blog?)

 
Comments
7 Comments »
Categories
JavaFX, widgetfx
Tags
java store, JavaFX, widgetfx
Comments rss Comments rss
Trackback Trackback

« Previous Entries

Publications

The most comprehensive book on the JavaFX Platform!

Free Refcard covering JavaFX 1.2

Categories

  • Announcements (11)
  • contest (3)
  • Events (14)
  • JavaFX (29)
  • JavaFX Mobile (1)
  • jfxtras (9)
  • Liferay (2)
  • presentation (4)
  • pro javafx (2)
  • SvJugFx (6)
  • Uncategorized (21)
  • Video (2)
  • widgetfx (9)

Affiliations

Awards

2009 JavaOne Rock Star!

rss Comments rss valid xhtml 1.1 design by jide powered by Wordpress get firefox