Announcement Announcement Module
Collapse
No announcement yet.
MigLayoutFormBuilder ? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • MigLayoutFormBuilder ?

    Hello

    Could we have a MIG based form layout builder?

    Seems to be the most intuitive swing layout manager.

    I can do most of the demo Contact form with the following.

    BR
    Carsten


    /**
    * Form layout builder that uses MIG layout http://www.miglayout.com/
    *
    * See http://www.miglayout.com/QuickStart.pdf
    * http://www.migcalendar.com/miglayout/cheatsheet.html
    * http://www.migcalendar.com/miglayout/whitepaper.html
    *
    * @author com
    *
    */

    public class MigLayoutFormBuilder extends AbstractFormBuilder {

    private MigLayout layout;

    private JPanel panel;

    public MigLayoutFormBuilder(BindingFactory bindingFactory,
    MigLayout migLayout) {
    super(bindingFactory);
    layout = migLayout;
    panel = new JPanel(migLayout);
    }

    public JComponent[] add(String property) {
    return add(property, "", "");
    }

    /**
    * Add property incl label
    *
    * @param property
    * the property name
    * @param labelGap
    * mig layout of JLabel for property
    * @param layoutStr
    * mig layout for component
    * @return
    */
    public JComponent[] add(String property, String labelGap, String layoutStr) {
    JComponent propertyComponent = createDefaultBinding(property)
    .getControl();
    JLabel l = createLabelFor(property, propertyComponent);
    panel.add(l, labelGap);
    panel.add(propertyComponent, layoutStr);
    return new JComponent[] { l, propertyComponent };
    }

    public void add(JComponent comp, String layoutStr) {
    panel.add(comp, layoutStr);
    }

    public JLabel addLabel(String property, String labelGap) {
    JLabel l = createLabelFor(property, null);
    panel.add(l, labelGap);
    return l;
    }

    /**
    *
    * @param property
    * @param labelGap
    * @param layoutStr
    * @return textArea, scrollpane with text area embedded
    */
    public JComponent[] addTextAreaAndLabel(String property, String labelGap,
    String layoutStr) {
    JTextArea textArea = (JTextArea) createTextArea(property);
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    JLabel l = createLabelFor(property, textArea);
    panel.add(l, labelGap);

    createBinding(property, textArea);
    JScrollPane scrollPane = new JScrollPane(textArea,
    ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
    ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED );
    add(scrollPane, layoutStr);
    return new JComponent[] { textArea, scrollPane };
    }

    public JPanel getPanel() {
    getBindingFactory().getFormModel().revert();
    return panel;
    }

    public void addHorizontalSeparator(String text, String layoutStr) {
    add(getComponentFactory().createLabeledSeparator(t ext), layoutStr);
    }

    }
Working...
X