You don't need to subclass TableView - you can just call getColumns().add(new 
TableView.Column(...));

On Oct 21, 2010, at 3:27 PM, Shahzad Bhatti wrote:

> Thanks Greg, that answers part of my question. The other half was how to 
> create table at runtime without defining it in the wtkx file as I wouldn't 
> know the # of columns. As TableView doesn't has setColumns method so I wasn't 
> sure the best way. I ended up subclassing TableView and overriding the 
> getColumns method to do it.
> 
> 
> On Oct 20, 2010, at 10:59 AM, Greg Brown wrote:
> 
>> Are you saying that you want to populate your table with rows that are 
>> defined as POJOs with a set of fixed bean properties as well as a 
>> variable-length list of indexed properties? For example:
>> 
>> public class Foo {
>>   public int getA() { ... }
>>   public String getB() { ... }
>>   public String[] getC() { ... }
>> }
>> 
>> I assume that you want the table columns to contain "a", "b", and then n 
>> additional columns corresponding to the elements in the array. Is that 
>> correct? If so there are a couple of ways you could go about this:
>> 
>> 1) Define a custom cell renderer that takes an array index as an argument. 
>> The render() method can cast the row object to an instance of Foo and call 
>> getC()[index] to get the cell data. Specify this renderer for each array 
>> element column in your table view.
>> 
>> 2) Model your row object as a dictionary instead of a bean with an array 
>> property. For example:
>> 
>> public class Foo implements Dictionary<String, Object> {
>>   public Object get(String key) { ... }
>> }
>> 
>> The get() method would map the "a" key to the getA() method, "b" to getB(), 
>> etc. and would map array index values to getC()[index].
>> 
>> I think I'd suggest #2 since it sounds like it probably wouldn't require you 
>> to write any custom renderers. Also, if it is possible to model your 
>> variable properties as key/value pairs instead of indexed array elements, I 
>> would definitely recommend doing so. The contents of an array are mutable, 
>> so any caller can modify them directly without the bean's knowledge. 
>> Exposing them via the Dictionary interface only promotes better 
>> encapsulation.
>> 
>> G
>> 
>> 
>> On Oct 20, 2010, at 12:14 PM, Shahzad Bhatti wrote:
>> 
>>> I need to create an editable table for my data structure that consists of 
>>> some fixed data elements and an array of variable size. Can someone provide 
>>> an example or tips for creating the table programmatically, where I can set 
>>> dynamic number of columns. Also, I would like to create a column for each 
>>> element of the variable-size array. How would I define accessor/setter for 
>>> that property (e..g instead of setArray/getArray, which takes or returns 
>>> arrays). Thanks.
>>> ______________________________________________
>>> 
>>> See  http://www.peak6.com/email_disclaimer.php
>>> for terms and conditions related to this email
>> 
> 

Reply via email to