Well, to change the text on a Label, you just have to call 
"label.setText(...);".  The "business logic" in your first button just has to 
keep track of how many times it has been pushed (i.e., which saying you want to 
display next), and set the correct text each time.

I'm not sure exactly what you're trying to do with the second button.... Do you 
just want it to make the label show up?  In order to do that, just do:
        BoxPane boxPane = ....  // Or could be set using a @BXML annotation
        Label label = new Label("initial saying");
        boxPane.add(label);

The repaint should be taken care of automatically by the skin(s).

Alternatively, you could always have the Label be included in the BoxPane, but 
just set it initially invisible ("visible='false'" in the .bxml file), and then 
in response to your second button press, call "label.setVisible(true);".

Am I correct in thinking that's what you want to accomplish?

HTH,
~Roger

-----Original Message-----
From: Ajay Bhat [mailto:a.ajay.b...@gmail.com] 
Sent: Thursday, July 18, 2013 11:23 AM
To: dev@pivot.apache.org
Subject: Re: How to highlight text using Pivot?

Hi Roger,

On Thu, Jul 18, 2013 at 9:31 PM, Roger L. Whitcomb <roger.whitc...@actian.com> 
wrote:
>
> Hi Ajay,
>         Label doesn't have near the capability of a TextArea (or
> TextPane) as far as manipulation of its parts.  It is meant to be a 
> single piece of text, all with the same attributes.  And, in fact, if 
> you want to change the color of a single word, then you're going to 
> have to use TextPane, and set up some text spans that have different 
> attributes.  Or you could use a series of Labels, each with one piece 
> of the text, and line them up with a BoxPane or FlowPane so it appears 
> they are one.  That way you could change the attributes of one Label 
> at a time.  Caveat:  I haven't actually tried this, but I'm pretty 
> sure you could play with the margins and such on the enclosing 
> container to make this work pretty well.  But TextPane is the 
> component that is actually meant for this sort of thing, but it is a 
> little bit more difficult to setup the document structure.  But, you 
> can take a look at the TextPaneDemo.java file for examples on working 
> with a TextPane, and applying styles to various pieces of text within 
> it.  You could make it read-only (with "setEditable(false)") so that 
> it simulates a Label in appearance.
>
> HTH,
> ~Roger Whitcomb
>

Great, I'll look into that.

I've got another (related?) question. Let's say I have a label defined inside a 
box pane and a list of strings, all of which are wise sayings. Let me have 2 
buttons.

> > Eg: Entered text is:
> >
> > The quick brown fox jumps over the lazy dog.
> >

Let the label be empty at first. Then if I click 1st button I need the label to 
display the first saying. I click the button again, I get the second saying and 
so on.
For the 2nd button if I click it, the label gets added to the box pane at 
first, then shows the saying, and then carries out repaint operation. How to do 
both of these?


--
Thanks and regards,
Ajay Bhat

Reply via email to