You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pivot.apache.org by Ajay Bhat <a....@gmail.com> on 2013/07/17 20:43:50 UTC

How to highlight text using Pivot?

Hi,

I'm using Pivot API for GUI application. I'd like to know how I can display
some text in a text area being highlighted, by basically being selected
when I use a ActionListener.

Eg: Entered text is:

The quick brown fox jumps over the lazy dog.

And I want to highlight the word 'quick' in the text area by having it
selected on clicking some button. How do I do it?

Thanks,
Ajay

Re: How to highlight text using Pivot?

Posted by Ajay Bhat <a....@gmail.com>.
Hi Roger,

Thanks so much for all the advice and direction. I'll get back to you if I
have any more questions


On Fri, Jul 19, 2013 at 10:48 PM, Roger L. Whitcomb <
Roger.Whitcomb@actian.com> wrote:

> Hi Ajay,
>         Well, your background is very interesting and encouraging, so
> thank you for your desire to contribute!
>         So, let me see if I can explain a bit more.  There definitely
> does have to be a "repaint" call somewhere in the Pivot or application
> code, because (obviously) nothing will get drawn without it.  In the
> Pivot environment the "skin" classes are responsible for both
> keyboard/mouse interaction and for painting onto the Java Graphics2D
> canvas. The interaction between the component classes and the skin
> classes is mostly done via "listeners", which are called to notify any
> interested code of changes that need to be processed.  So, whenever the
> underlying component data (such as the text of a Label) is changed, the
> appropriate listener is called (which, at least, will be the skin of
> that component), which then will invalidate the region, redo the
> component's layout, and then (eventually) repaint the new text.  So, all
> of that takes place in response to your application simply doing a
> "label.setText(...)", without any more intervention from the
> application.
>         The code you are seeing in the Vocabulary plugin looks like it
> is part of a custom container component, which is responsible for
> forcing appropriate repaints of its children.  But, from what you've
> told me so far of what you are doing I don't think you'll need any code
> like that in your application, since the appropriate "invalidate" and
> "repaint" calls will all happen pretty much automatically when you
> change the underlying data in the Pivot components.
>         BTW, I like your proposal, and I think Pivot will serve very
> well to build this application for Lucene.  I have actually been wanting
> other Apache projects to look to Pivot to build GUIs they might need, so
> this is a perfect example of what I've been hoping for!
>         As for suggestions on implementing features:
> 1) The menu bar is available inside a Frame as a MenuBar (see the
> http://pivot.apache.org/tutorials/menu-bars.html tutorial)
> 2) Tabbed documents are available using the TabPane class (tutorial
> here: http://pivot.apache.org/tutorials/tab-panes.html)
> 3) The numeric spinner ("Number of top terms:) is available.
> 4) The "Available fields" list can be done with a TableView
> (http://pivot.apache.org/tutorials/table-views.html).
> 5) The Analyzer tool's text field can likely be a TextArea if all you
> need to do is highlight a single piece of text, or a TextPane if you
> need to do more complex coloring, bolding, multiple highlights, etc.
> (tutorial here: http://pivot.apache.org/tutorials/text-areas.html for
> TextArea and there is a TextPane demo in the source code here:
> http://svn.apache.org/repos/asf/pivot/branches/2.0.x/demos/src/org/apach
> e/pivot/demos/text/ ).
> 6) The token list in the Analyzer could be a ListView (see tutorial
> here: http://pivot.apache.org/tutorials/lists.html).
> 7) The only component you will likely have to do some special work with
> is the top one where the left-hand column has highlighted and bold item
> descriptions, and the right-hand column has the associated values.
> Although you can probably do it relatively easily with a TableView and a
> custom renderer for the first column (see an example here:
> http://pivot.apache.org/tutorials/table-views.custom.html).
>
>         If you can download the Pivot source, I would build either the
> current "branches/2.0.x" code, which is very stable and should be
> released soon, or "trunk", which is pretty much the same except for some
> new stuff I'm working on to do remote file browsing.  The current
> release code (2.0.2) is okay too, but there are some improvements for
> version 2.0.3 that could be helpful.
>
>         Please continue to feel free to ask for help here.  As I said,
> this is something dear to my heart, so I will help as much as I can.
> Also, if there are things you feel could be improved in Pivot, you can
> definitely suggest those too.  The goal of the project is to be useful
> in creating GUIs just as you are doing.
>
> Thanks,
> ~Roger Whitcomb
>
>
> -----Original Message-----
> From: Ajay Bhat [mailto:a.ajay.bhat@gmail.com]
> Sent: Friday, July 19, 2013 6:22 AM
> To: dev@pivot.apache.org
> Subject: Re: How to highlight text using Pivot?
>
> Hi Roger,
>
> On Fri, Jul 19, 2013 at 12:02 AM, Roger L. Whitcomb <
> Roger.Whitcomb@actian.com> wrote:
>
> > 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.
> >
>
> Okay, got it.
>
> >
> > 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
> >
>
> I'm having a bit of trouble myself understanding the repaint() in my
> context and whether I need it or not.
>
> *Some background info:* I had attended the ASF ICFOSS Pilot programme in
> India [1] conducted by Luciano Resende [2] and as part of the program
> we're encouraged to contribute to the Apache community.
>
> I decided to do a project in Lucene[3]. The goal is to port some GUI
> features into the Luke application in the sandbox of Lucene [3] using
> Pivot, since Luke currently uses Thinlet (an LGPL licensed) API. [5]
>
> I studied some Pivot, did a proposal and used one of your earlier
> suggestions in the proposal.
>
> The proposal is here :
> https://docs.google.com/document/d/18Vu5YB6C7WLDxnG01BnZXFEKUC3EQYb0Y5_t
> CJFb_sc/
>
> Coming back to the problem :
> I'm seeing repaint() being used in the Vocabulary plugin (see Page 5 of
> above doc)
>
> The repaint() method as in src of Luke is :
> private void repaint(Object component, Object classname, Object part) {
>         Rectangle b = getRectangle(component, "bounds");
>         if (classname == "combobox") { // combobox down arrow
>             repaint(component, b.x + b.width - block, b.y, block,
> b.height); // icon?+
>         } else if ((classname == "tabbedpane") || // tab
>                 (classname == "menubar") || (classname == ":popup")) {
> // menuitem
>             Rectangle r = getRectangle(part, "bounds");
>             repaint(component, b.x + r.x, b.y + r.y, (classname ==
> ":popup") ? b.width : r.width, r.height);
>         }
>         /*Some more similar if statements*/
>    }
>
> It creates a rectangle object (from java Container class, IIRC) and sets
> bounds by calling this function.
>
>    private void repaint(Object component, int x, int y, int width, int
> height) {
>         while ((component = getParent(component)) != null) {
>             Rectangle bounds = getRectangle(component, "bounds");
>             if (bounds != null) {
>               x += bounds.x;
>               y += bounds.y;
>             }
>             Rectangle view = getRectangle(component, ":view");
>             if (view != null) {
>                 Rectangle port = getRectangle(component, ":port");
>                 x += -view.x + port.x;
>                 y += -view.y + port.y; //+ clip :port
>             }
>         }
>         repaint(x, y, width, height);
>     }
>
> I'm not seeing the point of creating bounds here. So I'm not sure why we
> need to repaint any item in Pivot or if we need to repaint at all. Maybe
> you could shed some light on this?
>
> Please go over my proposal and feel free to make any comments for how I
> could do the features.
>
> [1] http://community.apache.org/mentoringprogramme-icfoss-pilot.html
>
> [2] http://people.apache.org/~lresende
>
> [3] https://issues.apache.org/jira/browse/LUCENE-2562
>
> [4] https://svn.apache.org/repos/asf/lucene/sandbox/luke
>
> [5] http://luke.googlecode.com/svn/trunk/
>
> --
> Thanks and regards,
> Ajay Bhat
>



-- 
Thanks and regards,
Ajay Bhat

RE: How to highlight text using Pivot?

Posted by "Roger L. Whitcomb" <Ro...@actian.com>.
Hi Ajay,
	Well, your background is very interesting and encouraging, so
thank you for your desire to contribute!
	So, let me see if I can explain a bit more.  There definitely
does have to be a "repaint" call somewhere in the Pivot or application
code, because (obviously) nothing will get drawn without it.  In the
Pivot environment the "skin" classes are responsible for both
keyboard/mouse interaction and for painting onto the Java Graphics2D
canvas. The interaction between the component classes and the skin
classes is mostly done via "listeners", which are called to notify any
interested code of changes that need to be processed.  So, whenever the
underlying component data (such as the text of a Label) is changed, the
appropriate listener is called (which, at least, will be the skin of
that component), which then will invalidate the region, redo the
component's layout, and then (eventually) repaint the new text.  So, all
of that takes place in response to your application simply doing a
"label.setText(...)", without any more intervention from the
application.
	The code you are seeing in the Vocabulary plugin looks like it
is part of a custom container component, which is responsible for
forcing appropriate repaints of its children.  But, from what you've
told me so far of what you are doing I don't think you'll need any code
like that in your application, since the appropriate "invalidate" and
"repaint" calls will all happen pretty much automatically when you
change the underlying data in the Pivot components.
	BTW, I like your proposal, and I think Pivot will serve very
well to build this application for Lucene.  I have actually been wanting
other Apache projects to look to Pivot to build GUIs they might need, so
this is a perfect example of what I've been hoping for!
	As for suggestions on implementing features:
1) The menu bar is available inside a Frame as a MenuBar (see the
http://pivot.apache.org/tutorials/menu-bars.html tutorial)
2) Tabbed documents are available using the TabPane class (tutorial
here: http://pivot.apache.org/tutorials/tab-panes.html)
3) The numeric spinner ("Number of top terms:) is available.
4) The "Available fields" list can be done with a TableView
(http://pivot.apache.org/tutorials/table-views.html).
5) The Analyzer tool's text field can likely be a TextArea if all you
need to do is highlight a single piece of text, or a TextPane if you
need to do more complex coloring, bolding, multiple highlights, etc.
(tutorial here: http://pivot.apache.org/tutorials/text-areas.html for
TextArea and there is a TextPane demo in the source code here:
http://svn.apache.org/repos/asf/pivot/branches/2.0.x/demos/src/org/apach
e/pivot/demos/text/ ).
6) The token list in the Analyzer could be a ListView (see tutorial
here: http://pivot.apache.org/tutorials/lists.html).
7) The only component you will likely have to do some special work with
is the top one where the left-hand column has highlighted and bold item
descriptions, and the right-hand column has the associated values.
Although you can probably do it relatively easily with a TableView and a
custom renderer for the first column (see an example here:
http://pivot.apache.org/tutorials/table-views.custom.html).

	If you can download the Pivot source, I would build either the
current "branches/2.0.x" code, which is very stable and should be
released soon, or "trunk", which is pretty much the same except for some
new stuff I'm working on to do remote file browsing.  The current
release code (2.0.2) is okay too, but there are some improvements for
version 2.0.3 that could be helpful.

	Please continue to feel free to ask for help here.  As I said,
this is something dear to my heart, so I will help as much as I can.
Also, if there are things you feel could be improved in Pivot, you can
definitely suggest those too.  The goal of the project is to be useful
in creating GUIs just as you are doing.

Thanks,
~Roger Whitcomb


-----Original Message-----
From: Ajay Bhat [mailto:a.ajay.bhat@gmail.com] 
Sent: Friday, July 19, 2013 6:22 AM
To: dev@pivot.apache.org
Subject: Re: How to highlight text using Pivot?

Hi Roger,

On Fri, Jul 19, 2013 at 12:02 AM, Roger L. Whitcomb <
Roger.Whitcomb@actian.com> wrote:

> 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.
>

Okay, got it.

>
> 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
>

I'm having a bit of trouble myself understanding the repaint() in my
context and whether I need it or not.

*Some background info:* I had attended the ASF ICFOSS Pilot programme in
India [1] conducted by Luciano Resende [2] and as part of the program
we're encouraged to contribute to the Apache community.

I decided to do a project in Lucene[3]. The goal is to port some GUI
features into the Luke application in the sandbox of Lucene [3] using
Pivot, since Luke currently uses Thinlet (an LGPL licensed) API. [5]

I studied some Pivot, did a proposal and used one of your earlier
suggestions in the proposal.

The proposal is here :
https://docs.google.com/document/d/18Vu5YB6C7WLDxnG01BnZXFEKUC3EQYb0Y5_t
CJFb_sc/

Coming back to the problem :
I'm seeing repaint() being used in the Vocabulary plugin (see Page 5 of
above doc)

The repaint() method as in src of Luke is :
private void repaint(Object component, Object classname, Object part) {
        Rectangle b = getRectangle(component, "bounds");
        if (classname == "combobox") { // combobox down arrow
            repaint(component, b.x + b.width - block, b.y, block,
b.height); // icon?+
        } else if ((classname == "tabbedpane") || // tab
                (classname == "menubar") || (classname == ":popup")) {
// menuitem
            Rectangle r = getRectangle(part, "bounds");
            repaint(component, b.x + r.x, b.y + r.y, (classname ==
":popup") ? b.width : r.width, r.height);
        }
        /*Some more similar if statements*/
   }

It creates a rectangle object (from java Container class, IIRC) and sets
bounds by calling this function.

   private void repaint(Object component, int x, int y, int width, int
height) {
        while ((component = getParent(component)) != null) {
            Rectangle bounds = getRectangle(component, "bounds");
            if (bounds != null) {
              x += bounds.x;
              y += bounds.y;
            }
            Rectangle view = getRectangle(component, ":view");
            if (view != null) {
                Rectangle port = getRectangle(component, ":port");
                x += -view.x + port.x;
                y += -view.y + port.y; //+ clip :port
            }
        }
        repaint(x, y, width, height);
    }

I'm not seeing the point of creating bounds here. So I'm not sure why we
need to repaint any item in Pivot or if we need to repaint at all. Maybe
you could shed some light on this?

Please go over my proposal and feel free to make any comments for how I
could do the features.

[1] http://community.apache.org/mentoringprogramme-icfoss-pilot.html

[2] http://people.apache.org/~lresende

[3] https://issues.apache.org/jira/browse/LUCENE-2562

[4] https://svn.apache.org/repos/asf/lucene/sandbox/luke

[5] http://luke.googlecode.com/svn/trunk/

--
Thanks and regards,
Ajay Bhat

Re: How to highlight text using Pivot?

Posted by Ajay Bhat <a....@gmail.com>.
Hi Roger,

On Fri, Jul 19, 2013 at 12:02 AM, Roger L. Whitcomb <
Roger.Whitcomb@actian.com> wrote:

> 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.
>

Okay, got it.

>
> 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
>

I'm having a bit of trouble myself understanding the repaint() in my
context and whether I need it or not.

*Some background info:* I had attended the ASF ICFOSS Pilot programme in
India [1] conducted by Luciano Resende [2] and as part of the program we're
encouraged to contribute to the Apache community.

I decided to do a project in Lucene[3]. The goal is to port some GUI
features into the Luke application in the sandbox of Lucene [3] using
Pivot, since Luke currently uses Thinlet (an LGPL licensed) API. [5]

I studied some Pivot, did a proposal and used one of your earlier
suggestions in the proposal.

The proposal is here :
https://docs.google.com/document/d/18Vu5YB6C7WLDxnG01BnZXFEKUC3EQYb0Y5_tCJFb_sc/

Coming back to the problem :
I'm seeing repaint() being used in the Vocabulary plugin (see Page 5 of
above doc)

The repaint() method as in src of Luke is :
private void repaint(Object component, Object classname, Object part) {
        Rectangle b = getRectangle(component, "bounds");
        if (classname == "combobox") { // combobox down arrow
            repaint(component, b.x + b.width - block, b.y, block,
b.height); // icon?+
        } else if ((classname == "tabbedpane") || // tab
                (classname == "menubar") || (classname == ":popup")) { //
menuitem
            Rectangle r = getRectangle(part, "bounds");
            repaint(component, b.x + r.x, b.y + r.y, (classname ==
":popup") ? b.width : r.width, r.height);
        }
        /*Some more similar if statements*/
   }

It creates a rectangle object (from java Container class, IIRC) and sets
bounds by calling this function.

   private void repaint(Object component, int x, int y, int width, int
height) {
        while ((component = getParent(component)) != null) {
            Rectangle bounds = getRectangle(component, "bounds");
            if (bounds != null) {
              x += bounds.x;
              y += bounds.y;
            }
            Rectangle view = getRectangle(component, ":view");
            if (view != null) {
                Rectangle port = getRectangle(component, ":port");
                x += -view.x + port.x;
                y += -view.y + port.y; //+ clip :port
            }
        }
        repaint(x, y, width, height);
    }

I'm not seeing the point of creating bounds here. So I'm not sure why we
need to repaint any item in Pivot or if we need to repaint at all. Maybe
you could shed some light on this?

Please go over my proposal and feel free to make any comments for how I
could do the features.

[1] http://community.apache.org/mentoringprogramme-icfoss-pilot.html

[2] http://people.apache.org/~lresende

[3] https://issues.apache.org/jira/browse/LUCENE-2562

[4] https://svn.apache.org/repos/asf/lucene/sandbox/luke

[5] http://luke.googlecode.com/svn/trunk/

-- 
Thanks and regards,
Ajay Bhat

RE: How to highlight text using Pivot?

Posted by "Roger L. Whitcomb" <Ro...@actian.com>.
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.bhat@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 <Ro...@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

Re: How to highlight text using Pivot?

Posted by Ajay Bhat <a....@gmail.com>.
Hi Roger,

On Thu, Jul 18, 2013 at 9:31 PM, Roger L. Whitcomb
<Ro...@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

RE: How to highlight text using Pivot?

Posted by "Roger L. Whitcomb" <Ro...@actian.com>.
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

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

On Jul 18, 2013 12:13 AM, "Ajay Bhat" <a....@gmail.com> wrote:
>
> Hi,
>
> I'm using Pivot API for GUI application. I'd like to know how I can
display some text in a text area being highlighted, by basically being
selected when I use a ActionListener.
>

As a follow up to this question I'd also like to know how to highlight
text in a label

> Eg: Entered text is:
>
> The quick brown fox jumps over the lazy dog.
>
> And I want to highlight the word 'quick' in the text area by having it
selected on clicking some button. How do I do it?
>

Let's say I have the above sentence in a label and I need to highlight
'brown' by say changing color of the word to brown. I have the offset of
the beginning of the word. How to do it?

> Thanks,
> Ajay

Re: How to highlight text using Pivot?

Posted by Ajay Bhat <a....@gmail.com>.
On Jul 18, 2013 12:13 AM, "Ajay Bhat" <a....@gmail.com> wrote:
>
> Hi,
>
> I'm using Pivot API for GUI application. I'd like to know how I can
display some text in a text area being highlighted, by basically being
selected when I use a ActionListener.
>

As a follow up to this question I'd also like to know how to highlight text
in a label

> Eg: Entered text is:
>
> The quick brown fox jumps over the lazy dog.
>
> And I want to highlight the word 'quick' in the text area by having it
selected on clicking some button. How do I do it?
>

Let's say I have the above sentence in a label and I need to highlight
'brown' by say changing color of the word to brown. I have the offset of
the beginning of the word. How to do it?

> Thanks,
> Ajay

Re: How to highlight text using Pivot?

Posted by Ajay Bhat <a....@gmail.com>.
Thanks Roger.


On Thu, Jul 18, 2013 at 12:42 AM, Roger L. Whitcomb <
Roger.Whitcomb@actian.com> wrote:

> Hi Ajay,
>         There are two methods in TextArea that could be used:
> setSelection(int selectionStart, int selectionLength); or
> setSelection(Span selection);
>         If you already know the offset and length of where you want to
> select, then you can use the first one:
> ... in your ButtonPressListener ...
>                 int start = <starting offset of text to select>;
>                 int length = <length of text>;
>                 textArea.clearSelection();
>                 textArea.setSelection(start, length);
>
>         Alternatively, you can use the methods that involve a Span
> object:
>                 Span span = new Span(start, end);
>                 textArea.setSelection(span);
>
> HTH,
> ~Roger Whitcomb
>
> -----Original Message-----
> From: Ajay Bhat [mailto:a.ajay.bhat@gmail.com]
> Sent: Wednesday, July 17, 2013 11:44 AM
> To: dev@pivot.apache.org
> Subject: How to highlight text using Pivot?
>
> Hi,
>
> I'm using Pivot API for GUI application. I'd like to know how I can
> display some text in a text area being highlighted, by basically being
> selected when I use a ActionListener.
>
> Eg: Entered text is:
>
> The quick brown fox jumps over the lazy dog.
>
> And I want to highlight the word 'quick' in the text area by having it
> selected on clicking some button. How do I do it?
>
> Thanks,
> Ajay
>

RE: How to highlight text using Pivot?

Posted by "Roger L. Whitcomb" <Ro...@actian.com>.
Hi Ajay,
	There are two methods in TextArea that could be used:
setSelection(int selectionStart, int selectionLength); or
setSelection(Span selection);
	If you already know the offset and length of where you want to
select, then you can use the first one:
... in your ButtonPressListener ...
		int start = <starting offset of text to select>;
		int length = <length of text>;
		textArea.clearSelection();
		textArea.setSelection(start, length);

	Alternatively, you can use the methods that involve a Span
object:
		Span span = new Span(start, end);
		textArea.setSelection(span);

HTH,
~Roger Whitcomb

-----Original Message-----
From: Ajay Bhat [mailto:a.ajay.bhat@gmail.com] 
Sent: Wednesday, July 17, 2013 11:44 AM
To: dev@pivot.apache.org
Subject: How to highlight text using Pivot?

Hi,

I'm using Pivot API for GUI application. I'd like to know how I can
display some text in a text area being highlighted, by basically being
selected when I use a ActionListener.

Eg: Entered text is:

The quick brown fox jumps over the lazy dog.

And I want to highlight the word 'quick' in the text area by having it
selected on clicking some button. How do I do it?

Thanks,
Ajay