You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@pivot.apache.org by JohnRodey <ti...@yahoo.com> on 2010/06/18 21:05:48 UTC

Adding bolded text to TableView Cell

We've discussed before adding textual highlighting to a textarea, in which
case I created a decorator to draw a colored box around the selected text.

I would now like to bold certain words in a string within a tableview cell. 
I don't think the decorator approach will work, at least not as simply,
because drawing bolded text on top of the regular text will result in a
longer string (in most fonts) and the two will not match up.

Any ideas?
-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Adding-bolded-text-to-TableView-Cell-tp906255p906255.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Adding bolded text to TableView Cell

Posted by Greg Brown <gk...@mac.com>.
Is the bold state based on some conditional logic, or will it always be bold? If it is always bold, you can just create a new instance of TableViewCellRenderer for that column and set its font style to bold:

<TableView.Column name="myBoldColumn">
  <cellRenderer>
    <content:TableViewCellRenderer styles="{font:{bold:true}}"/>
  </cellRenderer>
</TableView.Column>

Otherwise, you can easily extend the TableViewCellRenderer class and override render() to make the text bold as needed:

public void render(...) {
    super.render(...);

    if (shouldBeBold) {
        Font font = (Font)getStyles().get("font");
        getStyles().put("font", font.deriveFont(Font.BOLD));
    }
}

Then set the cell renderer for that column to your custom renderer class, similar to what is shown above.

Hope this helps.

G

On Jun 18, 2010, at 3:05 PM, JohnRodey wrote:

> 
> We've discussed before adding textual highlighting to a textarea, in which
> case I created a decorator to draw a colored box around the selected text.
> 
> I would now like to bold certain words in a string within a tableview cell. 
> I don't think the decorator approach will work, at least not as simply,
> because drawing bolded text on top of the regular text will result in a
> longer string (in most fonts) and the two will not match up.
> 
> Any ideas?
> -- 
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Adding-bolded-text-to-TableView-Cell-tp906255p906255.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.


Re: Adding bolded text to TableView Cell

Posted by Greg Brown <gk...@mac.com>.
Oh, oops. Missed the "certain words" part.  :-(  Yeah, Pivot 2.0 is your best bet there. 


On Jun 18, 2010, at 3:40 PM, Noel Grandin wrote:

> In Pivot2.0 you would be able build your own Renderer around a
> TextArea, and use that Renderer in your TableView.
> 
> However, since that functionality is not yet fully available, I would
> suggest building a Renderer around a FlowPane, split the string up
> into Label's inside the FlowPane, and set the font style to bold on
> the correct Label components.
> 
> -- Noel Grandin
> 
> On Fri, Jun 18, 2010 at 21:05, JohnRodey <ti...@yahoo.com> wrote:
>> 
>> We've discussed before adding textual highlighting to a textarea, in which
>> case I created a decorator to draw a colored box around the selected text.
>> 
>> I would now like to bold certain words in a string within a tableview cell.
>> I don't think the decorator approach will work, at least not as simply,
>> because drawing bolded text on top of the regular text will result in a
>> longer string (in most fonts) and the two will not match up.
>> 
>> Any ideas?
>> --
>> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Adding-bolded-text-to-TableView-Cell-tp906255p906255.html
>> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
>> 


Re: Adding bolded text to TableView Cell

Posted by JohnRodey <ti...@yahoo.com>.
Now that Pivot 2.0 is out I was wondering if a tableview cell could support
rtf or if I would need to create my own renderer as noel stated back in
June.

I basically want to have a cell contain a sentence with certain words
bolded.

Thanks!
-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Adding-bolded-text-to-TableView-Cell-tp906255p2419020.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Adding bolded text to TableView Cell

Posted by Greg Brown <gk...@mac.com>.
Yeah, here it is:

http://svn.apache.org/repos/asf/pivot/branches/1.5.x/tutorials/src/org/apache/pivot/tutorials/filebrowsing/FileBrowsing.java

See the following lines:

    if (fileBrowserSheetMode == FileBrowserSheet.Mode.SAVE_AS) {
        fileBrowserSheet.setSelectedFile(new File(fileBrowserSheet.getRootDirectory(), "New File"));
    }

That example just uses the current root directory rather than changing it, but the result is the same.

G

On Jun 18, 2010, at 4:17 PM, Greg Brown wrote:

>> Do you have any ballpark guess on when 2.0 will be released?
> 
> I'd guess somewhere in the 6-9 month timeframe, but it is really too early to say at this point.
> 
>> Also I remember reading a forum or defect somewhere about being able to set
>> a default file name for the FileBrowserSheet when it loads.  1.4 did not
>> support that but I thought 1.5 would.  I can't seem to find that thread but
>> was wondering if you recall if that was incorporated?  I left in the
>> following code and thought when I upgraded to 1.5 it would work, but doesn't
>> seem to.
>> 
>> fileBrowserSheet.setSelectedFile(new File("somefile.txt"));
>> fileBrowserSheet.open(window, new SheetCloseListener() {...});
> 
> 
> I don't think relative files will work. The selected file has to be a valid path on the file system. You may also need to call fileBrowserSheet.setRootDirectory() to navigate to the right folder:
> 
> File rootDirectory = new File("/tmp/foo");
> fileBrowserSheet.setRootDirectory(rootDirectory);
> fileBrowserSheet.setSelectedFile(new File(rootDirectory, "somefile.txt"));
> 
> I didn't test this example though, so let me know if it doesn't work.
> 
> G
> 


Re: Adding bolded text to TableView Cell

Posted by Greg Brown <gk...@mac.com>.
> Do you have any ballpark guess on when 2.0 will be released?

I'd guess somewhere in the 6-9 month timeframe, but it is really too early to say at this point.

> Also I remember reading a forum or defect somewhere about being able to set
> a default file name for the FileBrowserSheet when it loads.  1.4 did not
> support that but I thought 1.5 would.  I can't seem to find that thread but
> was wondering if you recall if that was incorporated?  I left in the
> following code and thought when I upgraded to 1.5 it would work, but doesn't
> seem to.
> 
> fileBrowserSheet.setSelectedFile(new File("somefile.txt"));
> fileBrowserSheet.open(window, new SheetCloseListener() {...});


I don't think relative files will work. The selected file has to be a valid path on the file system. You may also need to call fileBrowserSheet.setRootDirectory() to navigate to the right folder:

File rootDirectory = new File("/tmp/foo");
fileBrowserSheet.setRootDirectory(rootDirectory);
fileBrowserSheet.setSelectedFile(new File(rootDirectory, "somefile.txt"));

I didn't test this example though, so let me know if it doesn't work.

G


Re: Adding bolded text to TableView Cell

Posted by JohnRodey <ti...@yahoo.com>.
Ok that would rok for me Noel, thanks.

Do you have any ballpark guess on when 2.0 will be released?

Also I remember reading a forum or defect somewhere about being able to set
a default file name for the FileBrowserSheet when it loads.  1.4 did not
support that but I thought 1.5 would.  I can't seem to find that thread but
was wondering if you recall if that was incorporated?  I left in the
following code and thought when I upgraded to 1.5 it would work, but doesn't
seem to.

fileBrowserSheet.setSelectedFile(new File("somefile.txt"));
fileBrowserSheet.open(window, new SheetCloseListener() {...});
-- 
View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Adding-bolded-text-to-TableView-Cell-tp906255p906343.html
Sent from the Apache Pivot - Users mailing list archive at Nabble.com.

Re: Adding bolded text to TableView Cell

Posted by Noel Grandin <no...@gmail.com>.
In Pivot2.0 you would be able build your own Renderer around a
TextArea, and use that Renderer in your TableView.

However, since that functionality is not yet fully available, I would
suggest building a Renderer around a FlowPane, split the string up
into Label's inside the FlowPane, and set the font style to bold on
the correct Label components.

-- Noel Grandin

On Fri, Jun 18, 2010 at 21:05, JohnRodey <ti...@yahoo.com> wrote:
>
> We've discussed before adding textual highlighting to a textarea, in which
> case I created a decorator to draw a colored box around the selected text.
>
> I would now like to bold certain words in a string within a tableview cell.
> I don't think the decorator approach will work, at least not as simply,
> because drawing bolded text on top of the regular text will result in a
> longer string (in most fonts) and the two will not match up.
>
> Any ideas?
> --
> View this message in context: http://apache-pivot-users.399431.n3.nabble.com/Adding-bolded-text-to-TableView-Cell-tp906255p906255.html
> Sent from the Apache Pivot - Users mailing list archive at Nabble.com.
>