Archive for May, 2010

James Weaver’s JavaFX Blog: A JavaFX 1.3 Custom Layout Example 0

With the new, improved, custom layout capabilities in JavaFX 1.3, I thought it’d be useful to post a simple example. This example defines a custom layout in JavaFX whose behavior is like the BorderLayout, familiar to most Java programmers. Here’s a screen shot:

Go to Source

Grid container support : JavaFX Composer 0

In JavaFX release 1.3 in preview package can be located Grid container (com.javafx.preview.layout.Grid). This container implements grid layout idiom to simplify organization of controls in form like layouts.

Go to Source

A JavaFX 1.3 Custom Layout Example 0

With the new, improved, custom layout capabilities in JavaFX 1.3, I thought it’d be useful to post a simple example.  This example defines a custom layout in JavaFX whose behavior is like the BorderLayout, familiar to most Java programmers.

Go to Source

A JavaFX 1.3 Custom Layout Example 0

With the new, improved, custom layout capabilities in JavaFX 1.3, I thought it’d be useful to post a simple example. This example defines a custom layout in JavaFX whose behavior is like the BorderLayout, familiar to most Java programmers.

Go to Source

A JavaFX 1.3 Custom Layout Example 0

With the new, improved, custom layout capabilities in JavaFX 1.3, I thought it’d be useful to post a simple example.  This example defines a custom layout in JavaFX whose behavior is like the BorderLayout, familiar to most Java programmers.  Here’s a screen shot:

Screen shot 2010-05-31 at 9.53.25 AM
There are actually two ways to create custom layouts in JavaFX: 

  1. Sub-class javafx.scene.layout.Container
  2. Create a javafx.scene.layout.Panel instance

Here is the code from today’s example that employs the first way.  Note that I’m leveraging the Node#id instance variable to supply the directional values needed by the traditional BorderLayout.

/*
 * BorderLayout.fx -
 * Example of subclassing Container to create a custom layout
 */

package containersubclasslayoutexample.layout;

import javafx.scene.layout.*;
import javafx.scene.layout.Container.*;

public class BorderLayout extends Container {
  var topHeight:Number;
  var bottomHeight:Number;
  var leftWidth:Number;
  var rightWidth:Number;

  override function doLayout():Void {
    for (node in getManaged(content)) {
      if (node.id == "top") {
        topHeight = getNodePrefHeight(node);
        setNodeWidth(node, width);
        setNodeHeight(node, getNodePrefHeight(node));
        positionNode(node, 0, 0);
      }
      else if (node.id == "bottom") {
        bottomHeight = getNodePrefHeight(node);
        setNodeWidth(node, width);
        setNodeHeight(node, getNodePrefHeight(node));
        positionNode(node, 0, height - bottomHeight);
      }
      else if (node.id == "left") {
        leftWidth = getNodePrefWidth(node);
        setNodeWidth(node, getNodePrefWidth(node));
        setNodeHeight(node, height - (topHeight + bottomHeight));
        positionNode(node, 0, topHeight);
      }
      else if (node.id == "right") {
        rightWidth = getNodePrefWidth(node);
        setNodeWidth(node, getNodePrefWidth(node));
        setNodeHeight(node, height - (topHeight + bottomHeight));
        positionNode(node, width - rightWidth, topHeight);
      }
      else if (node.id == "center") {
        setNodeWidth(node, width - (leftWidth + rightWidth));
        setNodeHeight(node, height - (topHeight + bottomHeight));
        positionNode(node, leftWidth, topHeight);
      }
    }
  }
  override function getPrefWidth(height:Number):Number {
    return width;
  }
  override function getPrefHeight(width:Number):Number {
    return height;
  }
}

Here is a code example of using the BorderLayout shown above.

/*
 * ContainerSubclassLayoutExample.fx -
 * Example of subclassing Container to create a custom layout
 */

package containersubclasslayoutexample;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.*;
import containersubclasslayoutexample.layout.BorderLayout;

var nodes = [
  Button {
    text: "Top"
    id: "top"
  },
  Button {
    text: "Bottom"
    id: "bottom"
  },
  Button {
    text: "Left"
    id: "left"
  },
  Button {
    text: "Right"
     id: "right"
  },
  Button {
    text: "Center"
    id: "center"
  }
];

Stage {
  var sceneRef:Scene;
  title: "Container Subclass Layout Example"
  scene: sceneRef = Scene {
    width: 500
    height: 300
    content: [
      BorderLayout {
        width: bind sceneRef.width
        height: bind sceneRef.height
        content: nodes
      }
    ]
  }
}

Lastly, here is an example of defining the BorderLayout custom layout functionality using the second way listed above, which is to create a Panel instance and override its behavior:

/*
 * PanelLayoutExample.fx -
 * Example of using a Panel to create a custom layout
 */

package panellayoutexample;

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.scene.layout.Container.*;

var nodes = [
  Button {
    text: "Center"
    id: "center"
  },
  Button {
    text: "Top"
    id: "top"
  },
  Button {
    text: "Bottom"
    id: "bottom"
  },
  Button {
    text: "Left"
    id: "left"
  },
  Button {
    text: "Right"
     id: "right"
  },
];

Stage {
  var panel:Panel;
  var sceneRef:Scene;
  title: "Panel Layout Example"
  scene: sceneRef = Scene {
    width: 500
    height: 300
    content: [
      panel = Panel {
        var topHeight:Number;
        var bottomHeight:Number;
        var leftWidth:Number;
        var rightWidth:Number;
        content: bind nodes
        width: bind sceneRef.width
        height: bind sceneRef.height
        onLayout: function():Void {
          for (node in getManaged(panel.content)) {
            if (node.id == "top") {
              topHeight = getNodePrefHeight(node);
              setNodeWidth(node, panel.width);
              setNodeHeight(node, getNodePrefHeight(node));
              positionNode(node, 0, 0);
            }
            else if (node.id == "bottom") {
              bottomHeight = getNodePrefHeight(node);
              setNodeWidth(node, panel.width);
              setNodeHeight(node, getNodePrefHeight(node));
              positionNode(node, 0, panel.height - bottomHeight);
            }
            else if (node.id == "left") {
              leftWidth = getNodePrefWidth(node);
              setNodeWidth(node, getNodePrefWidth(node));
              setNodeHeight(node, panel.height - (topHeight + bottomHeight));
              positionNode(node, 0, topHeight);
            }
            else if (node.id == "right") {
              rightWidth = getNodePrefWidth(node);
              setNodeWidth(node, getNodePrefWidth(node));
              setNodeHeight(node, panel.height - (topHeight + bottomHeight));
              positionNode(node, panel.width - rightWidth, topHeight);
            }
            else if (node.id == "center") {
              setNodeWidth(node, panel.width - (leftWidth + rightWidth));
              setNodeHeight(node, panel.height - (topHeight + bottomHeight));
              positionNode(node, leftWidth, topHeight);
            }
          }
        }
        prefWidth: function(height:Number):Number {
          return panel.width;
        }
        prefHeight: function(width:Number):Number {
          return panel.height;
        }
      }
    ]
  }
}

To learn more about using and creating layouts in JavaFX 1.3, see the blog posts that Amy Fowler has been writing on the subject, and the Custom Layouts chapter in the upcoming new edition of the Clarke/Bruno/Connors JavaFX book.

A note regarding the JavaFX RIA Exemplar Challenge: We have received several entries and I’m in the process of packaging them up and sharing them with the judges.  The winner will be announced in early June, 2010.

Regards,

Jim Weaver


Go to Source

CSS Background Images in JavaFX 1.3 0

Setting JavaFX 1.3 scene backgrounds in CSS probably doesn’t work like you think it does, but it is possible. This article shows several options for styling your Scene’s backgrounds from CSS including colors, gradients, and even images with positioning and repeating.

Go to Source

Review Java EE6 and JavaFX 1.3 – Part I, the back-end 0

In the first part of this review (the JavaEE6 back-end) I tested a small application which is a JSON REST service to be used as back-end for a JavaFX front-end. My conclusion for now is that JavaEE6 has a lot of new features which makes it a lot easier to use Java EE without extra libraries like Spring, Seam or Resteasy. I was able to make a back-end application which was noticeable fast with a low overhead in bandwidth and CPU usage.

Go to Source

JavaFX Talks Accepted at JavaOne 0

I am honored to be accepted by some great conferences to speak on JavaFX. Each of the talks I am giving is unique, which means more work for me, but is a great opportunity to talk about some different topics that I think are important for folks using JavaFX.

Go to Source

NetBeans IDE 6.9 RC1 is here 0

The NetBeans IDE is an award-winning integrated development environment available for Windows, Mac, Linux, and Solaris. The NetBeans project consists of an open-source IDE and an application platform that enable developers to rapidly create web, enterprise, desktop, and mobile applications using the Java platform, as well as JavaFX, PHP, JavaScript and Ajax, Ruby and Ruby on Rails, Groovy and Grails, and C/C++.

Go to Source

O JavaFX, What Art Thou? 0

I have read and started to learn about JavaFX twice and both times have been “strikes” in the sense that there wasn’t enough there to really use. Both of these forays into JavaFX occurred at the time of 2007 JavaOne and 2008 JavaOne as a result of the pomp and ceremony at these conferences regarding JavaFX. Both times, I stopped wasting my time because I realized that it wasn’t ready for prime time yet.

Go to Source

Next Page »