Search code examples
javagxt

GXT Repaint CollapsePanel title


I am facing a problem with CollapsePanel.

I need to change it's title when an event gets fired. So far I override createCollapsePanel of BorderLayout and add a listener to the event i need:

final BorderLayout layout = new BorderLayout()
{

    @Override
    protected CollapsePanel createCollapsePanel(final ContentPanel panel, final BorderLayoutData data)
    {
        final CollapsePanel result = super.createCollapsePanel(panel, data);
        panel.getHeader().addListener(Events.Change, new Listener<BaseEvent>()
        {
            @Override
            public void handleEvent(BaseEvent be)
            {
                result.setTitle(panel.getHeading());
                result.repaint();
                layout();
            }
        });
        result.setTitle(panel.getHeading());
        return result;
    }
};

The code above executes just fine, however result CollapsePanel never gets the new title.

Is there something I am missing? Thanks


Solution

  •     final BorderLayout layout = new BorderLayout()
        {
            @Override
            protected CollapsePanel createCollapsePanel(final ContentPanel panel, final BorderLayoutData data)
            {
                final CollapsePanel result = super.createCollapsePanel(panel, data);
    
                result.sinkEvents(Events.Change.getEventCode());
                panel.getHeader().addListener(Events.Change, new Listener<BaseEvent>()
                {
                    @Override
                    public void handleEvent(BaseEvent be)
                    {
                        result.getElement().getElementsByTagName("span").getItem(0).setInnerText(panel.getHeading());
                        PcTreeUI.this.layout(true);
                    }
                });
                result.setTitle(panel.getHeading());
                return result;
            }
        };