Thursday Jan 10, 2008

A Snapshot of the JavaFX World

Sun tech evangelist Inyoung Cho provided a great presentation this morning on the latest in the JavaFX world.[Read More]

Wednesday Jan 09, 2008

Swing Application Framework and Beans Binding

Okay, I admit it. I was the co-author of “Java Swing,” a book which was published by O'Reilly ten years ago. I also admit that I've had several ideas throughout the years as to what would make a decent framework for Swing applications, including support for cataloging actions and resources, and cacheing of session state (window size, position, etc.). So, it was with great relief that a few years ago, I found that Hans Meuller on the Swing team was taking on this task in the new Swing Application Framework (JSR 296). I was equally glad to see that the scope of this project was something that “could be learned in a day.”

If you've ever worked with threads in Swing, or even the SwingWorker class, you probably know that it can be a bit of a challenge. Fortunately, JSR 296 will allow you to create tasks that can be started and monitored with the use of a TaskMonitor. In addition, there is a TaskService class that can help you organize each of your tasks and fire them off.

The Swing Application Framework also supports various lifecycle methods that you get when extending specific framework classes, such as initialize(), startup(), ready(), and shutdown(). Just extend the appropriate class, override these methods, and you won't have to worry about trapping any obscure events and reacting to them again.

I was also very impressed by the resource injection. Basically, this means that you can do something like:

Resource file:

btnShowTime.text = Show current time!
btnShowTime.icon = refresh.png
Java class:
btnShowTime = new JButton();
btnShowTime.setName("btnShowTime");
And at this point, the resources are injected into the btnShowTime class automatically. In addition, you can even do something like this:

Resource File:

MyPanel.greetingMsg = Hello, %s, a string was injected!

Java class:
@Resource
String greetingMsg;

ResourceMap resource = ctxt.getResourceMap(MyPanel.class); 
resource.injectFields(this);
String personalMsg = String.format(greetingMsg, txtName.getText());
JOptionPane.showMessageDialog(this, personalMsg);

There is also a new API out there for beans binding. If you've never heard of beans binding before, the idea is that two properties in two different beans need to remain synchronized. This is actually part of JSR 295. In short, this means you can do something like this:
Property property1 = ELProperty.create(“${faceStyle}”);
Property property2 = BeanProperty.create(“value”);

Binding binding = Bindings.createAutoBinding(
UpdateStrategy.READ_WRITE,
object1, property1, // source
object2, property2); // target

binding.bind();
This will create a binding between the two objects such that if a value on either side changes, the other value will instantaneously be changed as well. It's simple, elegant, and it works! Kudos to Shannon Hickey and Scott Violet for a great addition to the Java APIs.

New Features In NetBeans 6.0

NetBeans evangelist Gregg Sporar drills down and discusses some of the latest and greatest features in NetBeans 6.0.[Read More]
About

Read about what goes on at Tech Days, what kinds of technical information is covered, and how the hands-on labs work for attendees.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today