Thanks for the answers. At least some of them :).
> * How do I make the Label control wrap its text? I gave it the
> style wrapText:true, but it has no effect.
>
> You need to make sure that the Label is in a container that will respect
> constrained preferred heights. For example, a TablePane, or a vertical
> BoxPane with the "fill" style set to true.
>
Neither of those quite works right, which I'll elaborate on below. But it
also strikes me as a kind of a broken model if styles only "work" if you
pick the right container.
> * How do I make the TextInput fields a reasonable size?
>
> Try setting the textSize property.
>
That works, thanks. So what, if anything, does setWidth do on a TextInput
component?
> * Is there a straightforward way to tell the standard dialog accelerators
> (Enter, Esc) what to do? ...
>
> You don't need to add explicit key listeners. You should open your dialog
> or sheet with a close listener - that is where you would put any "useful
> code".
>
Well, yes and no. I can certainly restructure the code so that pressing the
buttons just closes the sheet, and whoever calls open on the sheet does the
processing of the form based on the true/false result. But it means that I
can't keep the sheet open until the login succeeds -- I have to have a close
listener that initiates the login code, and if an error comes back, I reopen
the sheet, this time with an error message showing. And to show the user
that something is happening during the background authentication call, I
can't simply spin an activity indicator on the login sheet, but have to do
it somewhere else. That all seems clumsier than I'd like.
Furthermore, adding a key listener doesn't actually work. My keyPressed
method gets called, and it returns true ("consume the event") if keyCode ==
KeyCode.ENTER, but the dialog closes anyway. Is there a way to place the
listener so that it can consume the event before the default sheet closer
sees it?
* How do I space the buttons nicely? . . .
>
> I don't think you're necessarily missing anything - I think you are just
> expecting layout in Pivot to work the same way it does in WPF, which is not
> the case.
>
> If you don't want an element to stretch to fill the box pane, simply nest
> it in another box pane whose fill style is not set to true.
>
Yeah, okay, it's not WPF (I'll admit I didn't immediately understand the WPF
model when I started with it, either). Meanwhile, do you have a suggestion
for how one lays out two buttons in a horizontal row and achieve a pleasant
amount of space between them, perhaps even nicely balanced independent of
window width (e.g., equal amounts of whitespace to the left, to the right,
and in between)? In the dread WPF, I might give them center alignment in 2
columns of a Grid. Or I might set the buttons' horizontal margins to be a
pleasing width (not quite as good, since that remains static as the parent
window's size changes). What can I do in Pivot?
Also, I'd take advantage of form flags if possible, rather than adding your
> own custom error message label.
>
I'm not sure I see what's to be gained by that. Flags are a great feature
for a complicated form where you can pinpoint an area that's incorrect, but
for a login, these days we don't usually tell the user where the error was.
And I need a place to put the error message in any case (the Forms tutorial
certainly has one).
Anyway, back to the wrapping. Here's the way my code looks with the BoxPane
approach:
<my:LoginSheet title="Login to server"
xmlns:bxml="http://pivot.apache.org/bxml"
xmlns:my="com.fxpal.myunity"
xmlns="org.apache.pivot.wtk"
maximumWidth="300">
<BoxPane orientation="vertical" styles="{padding:4, fill:true}">
<Form>
<Form.Section>
<TextInput bxml:id="textInputName" Form.label="User Name"
textSize="15" />
<TextInput bxml:id="textInputPassword" Form.label="Password"
password="true" textSize="15" />
</Form.Section>
</Form>
<BoxPane orientation="horizontal"
styles="{fill:true, horizontalAlignment:'center'}">
<PushButton bxml:id="buttonLogin" buttonData="Login" />
<PushButton bxml:id="buttonCancel" buttonData="Cancel" />
</BoxPane>
<Separator />
<Label bxml:id="labelProblem" styles="{wrapText:true, color:'red'}"
/>
</BoxPane>
</my:LoginSheet>
I can tell it's trying to wrap the text, since some ascenders from the
second line are showing thru, but the label's height does not grow as
needed.
I also tried a more verbose TablePane:
<my:LoginSheet title="Login to server"
xmlns:bxml="http://pivot.apache.org/bxml"
xmlns:my="com.fxpal.myunity"
xmlns="org.apache.pivot.wtk"
maximumWidth="300">
<TablePane styles="{verticalSpacing:4}">
<columns>
<TablePane.Column width="1*" />
</columns>
<TablePane.Row height="1*">
<Form>
<Form.Section>
<TextInput bxml:id="textInputName" Form.label="User
Name"
textSize="15" />
<TextInput bxml:id="textInputPassword"
Form.label="Password"
password="true" textSize="15" />
</Form.Section>
</Form>
</TablePane.Row>
<TablePane.Row height="-1">
<BoxPane orientation="horizontal" styles="{fill:true,
horizontalAlignment:'center'}">
<PushButton bxml:id="buttonLogin" buttonData="Login" />
<PushButton bxml:id="buttonCancel" buttonData="Cancel" />
</BoxPane>
</TablePane.Row>
<TablePane.Row height="-1">
<Separator />
</TablePane.Row>
<TablePane.Row height="-1">
<Label bxml:id="labelProblem" styles="{wrapText:true,
color:'red'}" />
</TablePane.Row>
</TablePane>
</my:LoginSheet>
This also did not result in a taller label. The TablePane.Row height value
of -1 doesn't seem to be documented anywhere, other than indirectly in the
TablePane tutorial, but I'm guessing it means something like "the exact
height you need". If I change the height of the first row to "1*", as in
some examples I've seen (even though it isn't what I mean), the behavior is
a little different -- the label grows with the wrapped text, but at the
expense of the first row. That *really *isn't what I mean.