Sunday September 03, 2006
Swing Components and Visual Library 2.0
I wasn't entirely correct a few days ago when I said that the Visual Library 2.0 doesn't let you use Swing components. Even though the widgets that you create (such as icons and labels) are not Swing components, you can still use Swing components in various ways. They're never the central focus of an implementation of the Visual Library 2.0, but they can play good supportive roles. Here, for example, is a JComboBox in action, letting you select a different map:
The only difference between this JComboBox and standard JComboBoxes is that this one can be moved (with the mouse) around the map. Here's the code that makes that posible:
private Widget createMoveableComponent(Component component) {
Widget widget = new Widget(this);
widget.setLayout(LayoutFactory.createVerticalLayout());
widget.setBorder(BorderFactory.createLineBorder(Color.BLACK));
widget.getActions().addAction(normalMoveAction);
LabelWidget label = new LabelWidget(this, "Map Choice:");
label.setOpaque(true);
label.setForeground(Color.WHITE);
label.setBackground(Color.BLACK);
widget.addChild(label);
widget.addChild(new ComponentWidget(this, component));
pos += 100;
widget.setPreferredLocation(new Point(pos, pos));
return widget;
}
The only thing is that you can't see the label, because of the map. I think that's a bug. However, I'm okay with that because I can still use the invisible label to drag the menu around the map.
So, the method above receives a component. Here is that component:
mapChoices = new JComboBox(new String[] { "Land Map", "Satellite Map"});
mapChoices.addActionListener(this);
mainLayer.addChild(createMoveableComponent(mapChoices));
So, a standard ActionListener is attached to the JComboBox, for handling the change in the maps. Then, the JComboBox is added to the layer (which is like a glass pane over the 'scene', which is the top root of a Visual Library implementation) and the call is made to the createMoveableComponent() method that is shown above.
In this case, when the map is changed, this is what the user sees:
Pretty cool. So, there's a pretty strong role that Swing components can play in Visual Library 2.0 implementations.
Sep 03 2006, 03:51:56 AM PDT Permalink
Posted by Pavan on September 03, 2006 at 11:27 AM PDT #
Posted by Geertjan on September 03, 2006 at 11:46 AM PDT #
Posted by pavan on September 03, 2006 at 06:20 PM PDT #
Posted by Geertjan on September 03, 2006 at 07:14 PM PDT #
Posted by pavan on September 03, 2006 at 09:16 PM PDT #
Posted by Geertjan on September 03, 2006 at 09:22 PM PDT #
Posted by pavan on September 03, 2006 at 10:49 PM PDT #
Posted by Geertjan on September 03, 2006 at 10:51 PM PDT #
Posted by Pavan on September 03, 2006 at 11:15 PM PDT #
Posted by Augusto on September 09, 2006 at 01:37 AM PDT #
Posted by Geertjan on September 09, 2006 at 01:48 AM PDT #
Posted by Geertjan on September 09, 2006 at 01:49 AM PDT #
very interesting post
thanx!
Posted by Swing Components Library on September 28, 2007 at 10:45 AM PDT #
hi Geertjan
can i use visual library for Swing components instead of images as expl in http://platform.netbeans.org/tutorials/nbm-visual_library.html
Posted by ags on April 29, 2008 at 10:32 PM PDT #


