Results 1 to 3 of 3

Thread: Binding multiple properties into a single component

  1. #1
    Join Date
    Aug 2004
    Location
    Columbus, OH
    Posts
    65

    Default Binding multiple properties into a single component

    I have multiple checkboxes I would like the GUI to render in a JPanel with a particular layout.

    The builder concept expects a one-to-one relationship between the binding and the resulting JComponent. The JComponent is added to the form individually using the builder.add(propertyName) method. This works fine for simple cases.

    In my situation, I have the same one-to-one relationship between my bindings and the resulting JComponent. The only difference is I want multiple JComponents to be added into a single JPanel, and that JPanel is added to the builder.

    In code, it might look like:
    JPanel wrapper = new JPanel();
    builder.add(new String[] {"prop1", "prop2"}, wrapper);

    Is there any workaround, hack, supported option, hope for this to work?

  2. #2
    Join Date
    Aug 2004
    Posts
    229

    Default

    The thing to remember is that the builder is simply a helper class to help construct the visual layout of forms. Conceivably, it's entirely possible to create the return component of the "createFormControl" method manually - meaning you would manually bind properties to controls via BindingFactory and manually add them to some return component/panel. The form builder is designed to handle the most common cases. The builder also happens to include convenience methods that take care of binding properties to components and then adding them to the form. As things stand now, you will probably have to manually bind those components, build out your JPanel, and then add that to the form, rather than relying on the builder to bind the components. I'm doing this off the top of my head, so I'm not sure of its viability, but the basic idea is:
    Code:
      SwingBindingFactory bf = (SwingBindingFactory)getBindingFactory();
      TableFormBuilder fb = new TableFormBuilder(bf);
      .. add simple/normal properties using the TableFormBuilder ...
      JPanel panel = new JPanel();
      panel.add(bf.createBinding("prop1").getControl());
      panel.add(bf.createBinding("prop2").getControl());
      TableLayoutBuilder tlb = fb.getLayoutBuilder();
      tlb.cell(panel, ... attributes...);
      .. maybe add more simple properties via TableFormBuilder here ...
      return fb.getForm();
    TableFormBuilder uses a TableLayoutBuilder to actually add components and lay them out. I simply extract the TableLayoutBuilder and directly add my custom component, bypassing TableFormBuilder and its need to have a Binding for the component. You may have to look at TableLayoutBuilder for usage (and especially look at how TableFormBuilder uses it). We will probably want an easier way to do this in the future, but for now this should work.

    - Andy

  3. #3
    Join Date
    Aug 2004
    Location
    Columbus, OH
    Posts
    65

    Default

    Thanks for the tip Andy. I didn't think of bypassing the builder to go directly to the layout.

    I had previously extended TableFormBuilder to be able to pass a boolean value to all add() methods to determine whether a JLabel should be created or not. Since I had this subclass already, I added an add(JComponent, attributes) method.

Similar Threads

  1. FlowExecutionStorage in a DB
    By cacho in forum Web Flow
    Replies: 7
    Last Post: Oct 19th, 2009, 03:36 PM
  2. Binding composite properties with DataBinder
    By dhewitt in forum Architecture
    Replies: 16
    Last Post: Jun 1st, 2007, 06:22 AM
  3. Replies: 9
    Last Post: Jul 20th, 2006, 04:20 PM
  4. Replies: 0
    Last Post: May 8th, 2005, 02:15 AM
  5. Replies: 2
    Last Post: Aug 17th, 2004, 04:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •