TreeTable grouping row

View: New views
3 Messages — Rating Filter:   Alert me  

TreeTable grouping row

by Mike Katz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Is it possible to render the whole row in a grouping table as one long continuous title? I.e. if the grouping is done on the 2nd column, the expander icon and the title would start in the first column and continue along?

Re: TreeTable grouping row

by James Lemieux :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Mike,

   It can be done but it requires subclassing JTable and overriding getCellRect(...);

You can see the technique in action in the table we use in our IssuesBrowser demo. Specifically, check out JSeparatorTable here:

https://glazedlists.dev.java.net/source/browse/glazedlists/extensions/issuesbrowser/source/com/publicobject/misc/swing/JSeparatorTable.java?rev=1.6&view=log

(note, JSeparatorTable is not officially supported by Glazed Lists... it is meant as demo code only)

James

On Thu, Aug 21, 2008 at 8:04 AM, Mike Katz <michael.katz@...> wrote:

Is it possible to render the whole row in a grouping table as one long
continuous title? I.e. if the grouping is done on the 2nd column, the
expander icon and the title would start in the first column and continue
along?
--
View this message in context: http://www.nabble.com/TreeTable-grouping-row-tp19090279p19090279.html
Sent from the GlazedLists - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...



Re: TreeTable grouping row

by Brian Merrill :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Mike Katz wrote:
> Is it possible to render the whole row in a grouping table as one long
> continuous title? I.e. if the grouping is done on the 2nd column, the
> expander icon and the title would start in the first column and continue
> along?
>  
I just did this myself a couple of days ago myself using
TreeTableSupport and leveraging the standard Glazedlists TreeList
functionality.
The way I did it was to just extend the standard JTable.  The 3 pieces
you need to reimplement/borrow from the JSeparator example are:
-The SpanTableUI class (I changed JSeparatorTable to be just a regular
JTable within SpanTableUI)
-public Rectangle getCellRect(int row, int column, boolean includeSpacing)
-public Rectangle getCellRectWithoutSpanning(int row, int column,
boolean includeSpacing)

The the constructor of your custom JTable would be something like:
public SpanTable()
{
    super();
    //Initialize eventlist pipeline...
    EventTableModel <RowItem> eventTableModel = new EventTableModel
<RowItem>(treeList, tableFormat);
    setModel(eventTableModel);

    setUI(new SpanTableUI());
   
    TreeTableSupport treeTableSupport = TreeTableSupport.install(this,
treeList, treeColumnIndex);
    treeTableSupport.setShowExpanderForEmptyParent(false);
    treeTableSupport.setDelegateRenderer(new RowItemRenderer());
}

Then override JTable.getCellRenderer, something like:
@Override
    public TableCellRenderer getCellRenderer(int row, int column)
    {      
        RowItem rowItem = (RowItem)getEventTableModel().getElementAt(row);
        if (rowItem.getIsTitle())
        {
            return treeTableSupport.getRenderer();
        }
       
        //otherwise business as usual
        return super.getCellRenderer(row, column);
    }

Then in your "RowItemRenderer" (assuming it extends
DefaultTableCellRenderer) you could do something like:
@Override
    public Component getTableCellRendererComponent(JTable table, Object
value, boolean isSelected, boolean hasFocus, int row, int column)
    {
       if (value instanceof RowItem)
       {
             RowItem item = (RowItem)value;
             if (item.getIsTitle())
             {
                String title = titleFormat.format(new Object []
{item.getFirstValue().toString(), item.getSecondValue().toString()});
                setText(title);
                return this;
             }
             else
             {
                 setText(item.getValue())
             }
       }
       return this;
    }

That should then give you a JSeparatorTable-like look wherever you need
it but leverage the same icons and functionality of the regular GL
TreeTable.

Hope that helps,
Brian

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...

LightInTheBox - Buy quality products at wholesale price!