Two questions with MigLayout

27 views
Skip to first unread message

SurfMan

unread,
Dec 2, 2010, 10:12:34 AM12/2/10
to JavaBuilders
Hi,

I' ll start with a quick intro of what I am trying to accomplish here.
My application has the ability to download serverside information
generated by our Drupal CMS. It should be able to display dates,
labels, buttons, textfields etc. To make this generic, it soon started
to get messy: if (type.equals("date")), so I used Google to run into
this project, and decided to give this a spin. I use MigLayout
extensively in my application, and I love it. That's why I was really
excited to see the support from JavaBuilder like this.

My new idea was to generate a YAML String using PHP on the server,
send that to the component that displays the news using JavaBuilder. I
got the basics working and now I run into two MigLayout issues:

1) If I execute SwingJavaBuilder.build(this, someYamlString) multiple
times, I have the feeling that the MigLayout instance is reused. If I
remove the initial [[debug]] in my YAML String, reload my component,
i.e. execute SwingJavaBuilder.build(...) again, the debugging grid
stays. Is there a way to tell JavaBuilder *not* to reuse instances of
MigLayout?

2) I can't seen to omit the components names in the MigLayout. For
example, I have this YAML String, but it doesn't spit out my labels:

JPanel(name=mainpanel):
- JLabel(name=label1, text=Ideo Saluto)
- JLabel(name=label2, text=Pagus Letalis Aptent Os Molior Importunus
Abbas)
- JLabel(name=label3, text=Dignissim)
- MigLayout : |
[[wrap 1]]

This will tell MigLayout that after each component a new line begins.
This is the same what I often do in code:

JPanel mainpanel = new JPanel( new MigLayout("wrap 1"));
mainpanel.add(label1);
mainpanel.add(label2);
mainpanel.add(label3);

If I mention all the labels they will display:

JPanel(name=mainpanel):
- JLabel(name=label1, text=Ideo Saluto)
- JLabel(name=label2, text=Pagus Letalis Aptent Os Molior Importunus
Abbas)
- JLabel(name=label3, text=Dignissim)
- MigLayout : |
[[wrap 1]]
label1
label2
label3

Is there a way to tell the MigLayout in the YAML String to just add
all components to the end?

Thanks for the awesome stuff that you are creating. Keep up the good
work!

WarnerJan Veldhuis
The Netherlands

Jacek Furmankiewicz

unread,
Dec 2, 2010, 10:22:05 AM12/2/10
to JavaBuilders
If you are executing .build() multiple times within the same component
(something it was never designed to to)
it will always reuse existing components it can find. This is by
design, across all components, not just MigLayout.

We basically handle auto-creation of components or using existing ones
if we can find them.
If you are calling it within a new instance of a your JPanel then it
should always create a new one.

For the other MigLayout question, the DSL assumes you will always
layout the controls and specify them.

If you want to use the more MigLayout-specific syntax, it is covered
in the book. Look in the MigLayout section.
you can specify all the properties manually and then just pass it a
list of components

Jacek

Reply all
Reply to author
Forward
0 new messages