PDA

View Full Version : How to fit a TabPanel in a Viewport



sarsipius
24 Nov 2011, 11:59 PM
Hi,

I try to code a module in which a TabPanel need to be rendered

I don't find which layout I need to apply to the viewport in order to use the whole space for the TabPanel

Here is the code:



public class Module implements EntryPoint {

public void onModuleLoad() {
GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() {
public void onUncaughtException(Throwable e) {
MessageBox.alert("Error", e.getMessage(), null);
}
});

Viewport viewport = new Viewport();
viewport.setLayout(new BorderLayout());

ContentPanel cp = new ContentPanel();
cp.setHeading("Panel");
cp.setLayout(new FitLayout());

TabPanel tabPanel = new TabPanel();
tabPanel.setBodyBorder(false);
tabPanel.setBorderStyle(false);
tabPanel.setResizeTabs(false);
tabPanel.setAnimScroll(true);
tabPanel.setTabScroll(true);
tabPanel.setCloseContextMenu(true);

TabItem tabItem = new TabItem("Item");
tabItem.setLayout(new FitLayout());
tabItem.setClosable(false);
tabItem.add(cp);

viewport.add(tabPanel, new BorderLayoutData(LayoutRegion.CENTER));

RootPanel.get().add(viewport);
}

}


Could someone try it and help me?
Thanks

Colin Alworth
28 Nov 2011, 1:33 PM
You are setting the layout of the viewport to be borderlayout, but dont seem to be using it:


viewport.setLayout(new BorderLayout());

Instead, set the layout to be FitLayout, and the child of the viewport (the tab panel) will be always sized to use all space.


viewport.setLayout(new FitLayout());

sarsipius
28 Nov 2011, 1:40 PM
no you're wrong



viewport.add(tabPanel, new BorderLayoutData(LayoutRegion.CENTER));


and I tried FitLayout, RowLayout, CenterLayout, etc. but the TabPanel didn't fit

Colin Alworth
28 Nov 2011, 2:23 PM
Sorry, which part am I wrong about? That you are using the BorderLayout, or that the FitLayout doesn't work?

From the code you are quoting, it looks like you might be focusing on the when you add the tab panel to the viewport - I am talking about configuring the viewport.

Looking again at your original sample, I would modify it like this:


public class Module implements EntryPoint {

public void onModuleLoad() {
GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() {
public void onUncaughtException(Throwable e) {
MessageBox.alert("Error", e.getMessage(), null);
}
});

Viewport viewport = new Viewport();
viewport.setLayout(new FitLayout());

ContentPanel cp = new ContentPanel();
cp.setHeading("Panel");
cp.setLayout(new FitLayout());

TabPanel tabPanel = new TabPanel();
tabPanel.setBodyBorder(false);
tabPanel.setBorderStyle(false);
tabPanel.setResizeTabs(false);
tabPanel.setAnimScroll(true);
tabPanel.setTabScroll(true);
tabPanel.setCloseContextMenu(true);

TabItem tabItem = new TabItem("Item");
tabItem.setLayout(new FitLayout());
tabItem.setClosable(false);
tabItem.add(cp);

viewport.add(tabPanel);

RootPanel.get().add(viewport);
}
}

sarsipius
28 Nov 2011, 10:54 PM
both :)

I know how to use layouts and I assure you that the FitLayout doesn't work

if you have 10 seconds to try my code, you'll see it

you can even replace


viewport.add(tabPanel);

by


][/FONT]viewport.add(cp);

and it works fine

so I tell you this is probably an issue with the TabPanel object but I don't know how to fix it

gishmo
28 Nov 2011, 11:40 PM
It looks like it is not a layout problem.

I miss the statement where you add your tabItem to your tabPanel.

sarsipius
29 Nov 2011, 12:14 AM
you're right and I'm really ashamed!
thank you

Colin Alworth
29 Nov 2011, 8:11 AM
Nothing to be ashamed about – I should have caught that too. Thanks gishmo.