-
24 Nov 2011 11:59 PM #1
Answered: How to fit a TabPanel in a Viewport
Answered: How to fit a TabPanel in a Viewport
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:
Could someone try it and help me?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); } }
Thanks
-
Best Answer Posted by gishmo
It looks like it is not a layout problem.
I miss the statement where you add your tabItem to your tabPanel.
-
28 Nov 2011 1:33 PM #2
You are setting the layout of the viewport to be borderlayout, but dont seem to be using it:
Instead, set the layout to be FitLayout, and the child of the viewport (the tab panel) will be always sized to use all space.Code:viewport.setLayout(new BorderLayout());
Code:viewport.setLayout(new FitLayout());
-
28 Nov 2011 1:40 PM #3
no you're wrong
and I tried FitLayout, RowLayout, CenterLayout, etc. but the TabPanel didn't fitCode:viewport.add(tabPanel, new BorderLayoutData(LayoutRegion.CENTER));
-
28 Nov 2011 2:23 PM #4
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:
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 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); } }
-
28 Nov 2011 10:54 PM #5
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
byCode:viewport.add(tabPanel);
[code]viewport.add(cp);[/code]
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
-
28 Nov 2011 11:40 PM #6Ext GWT Premium Member
- Join Date
- Aug 2010
- Location
- Germany, Solingen
- Posts
- 226
- Vote Rating
- 2
- Answers
- 4
It looks like it is not a layout problem.
I miss the statement where you add your tabItem to your tabPanel.
-
29 Nov 2011 12:14 AM #7
you're right and I'm really ashamed!
thank you
-
29 Nov 2011 8:11 AM #8
Nothing to be ashamed about – I should have caught that too. Thanks gishmo.


Reply With Quote