PDA

View Full Version : TabItem OnClick



FireGlow
10 Sep 2009, 8:09 AM
Hey there!

I'm searching for an opportunity to change the onClick event of a TabItem!

Normally it changes to the TabItem and shows its content.

altough I don't want that it shows its content, but to call a personal method.

I can't override the onClick-Method... don't really now why!

Any ideas?

Thanks a lot

FireGlow

francescoNemesi
10 Sep 2009, 10:12 PM
You need to add a listener to the click event, set event.setCancelled(true) to stop the event and then call your method.

FireGlow
11 Sep 2009, 2:38 AM
I tried this, but it didn't work:



class QuestionAddTabItem
extends TabItem
{
QuestionAddTabItem() {
this.setIconStyle( "icon-question-add" );
this.setClosable( false );

this.addListener( Events.OnClick, new Listener<ComponentEvent>(){

public void handleEvent( ComponentEvent be ) {
be.setCancelled( true );
System.out.println("TEST");

}

});
}
}

FireGlow
11 Sep 2009, 3:00 AM
ok wrong event chosen... but the problem is I can only react after selecting, not before!



class QuestionAddTabItem
extends TabItem
{
QuestionAddTabItem() {
this.setIconStyle( "icon-question-add" );
this.setClosable( false );


this.addListener(Events.Select, new Listener<TabPanelEvent>()
{

public void handleEvent( TabPanelEvent be ) {
be.setCancelled( true );
System.out.println("TEST");
}

});
}
}



Is it possible to cancel the selection itself? I tried the Events.OnSelect but it didn't work...

sven
11 Sep 2009, 7:49 AM
TabPanel fires an Event.BeforeSelect event. You can listen to that and cancel it if you dont want to allow the change

FireGlow
12 Sep 2009, 3:47 AM
Yep, that works out. Thanks!