It seems that NorthSouthContainer can ajust the height of north widget.
Can BorderLayoutContainer do the same one?
(gxt version: 3.1.1)
public void onModuleLoad() {
final BorderLayoutContainer cont = new BorderLayoutContainer();
// final NorthSouthContainer cont = new NorthSouthContainer();
final ToolBar bar = new ToolBar();
bar.add(new TextButton("tool bar"));
cont.setNorthWidget(bar);
final ContentPanel panel = new ContentPanel();
panel.setHeadingText("content panel");
cont.setCenterWidget(panel);
// cont.setSouthWidget(panel);
final Viewport vp = new Viewport();
vp.add(cont);
RootPanel.get().add(vp);
}
NorthSouthContainer:
BorderLayoutContainer:
I know there are display bugs with that view. I'm not sure if it can be dynamically sized, we specifically set the height for it.
final BorderLayoutData northData = new BorderLayoutData(<height>);
cont.setNorthWidget(bar, northData);
You may have to add the toolbar into another container that deals with size better, ours is a HorizontalLayoutContainer inside of a ContentPanel.
Related
When put all widgets in one container, the gridlayout could align normally.
But for some reason, I need to put some widgets to a sub-container such as the composite as below. The alignment is different.
So the question is: Is there a container that has no effect on the gridlayout?
Ps: I know that can use white space as a workaround, but...
Code:
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
GridLayoutFactory.fillDefaults().numColumns(2).margins(8, 3).applyTo(shell);
new Label(shell, 0).setText("Label1");
new Text(shell, 0);
new Label(shell, 0).setText("A long Label");
new Text(shell, 0);
Composite composite = new Composite(shell, 0);
GridDataFactory.fillDefaults().span(2, 1).applyTo(composite);
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(composite);
new Label(composite, 0).setText("Label22");
new Text(composite, 0);
new Label(composite, 0).setText("Label223");
new Text(composite, 0);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
Result:
There is no container that can used like this. Sticking to a single composite is by far the easiest way to aligh the labels.
It is possible to specify the widthHint of the GridData for a label to specify the width. You would have to calculate the width required using something like:
List<Control> labels = ... list of Label controls
final int width = labels.stream()
.mapToInt(label -> label.computeSize(SWT.DEFAULT, SWT.DEFAULT).x)
.max()
.getAsInt();
final var labelData = GridDataFactory.swtDefaults().hint(width, SWT.DEFAULT);
labels.forEach(labelData::applyTo);
I am facing a little issue when using BorderLayoutContainer in my App.
I just want to have a center panel and south panel but I get a strange blue margin around my south panel (see the image below).
Find my sources below.
private Widget getContainer() {
SimpleContainer sc = new SimpleContainer();
BorderLayoutContainer blc = new BorderLayoutContainer();
ContentPanel validationView = new ContentPanel();
validationView.setHeadingText("Validation");
ContentPanel center = new ContentPanel();
center.add(editorMVP.getDisplay());
center.setHeaderVisible(false);
center.setBorders(false);
blc.setCenterWidget(center);
BorderLayoutData southData = new BorderLayoutData(250);
southData.setCollapsible(true);
southData.setSplit(true);
southData.setCollapsed(true);
blc.setSouthWidget(validationView, southData);
blc.collapse(LayoutRegion.SOUTH);
sc.add(blc);
return sc;
}
Can anybody help me solve this please?
EDIT: I have been able to remove this margin with using a SimpleContainer instead of a ContentPanel. But I have now a blue background I want to get rid off. Any idea?
private Widget getContainer() {
SimpleContainer sc = new SimpleContainer();
BorderLayoutContainer blc = new BorderLayoutContainer();
ContentPanel validationView = new ContentPanel();
validationView.setHeadingText("Validation");
SimpleContainer center = new SimpleContainer();
center.add(editorMVP.getDisplay());
blc.setCenterWidget(center);
BorderLayoutData southData = new BorderLayoutData(250);
southData.setCollapsible(true);
southData.setSplit(false);
southData.setCollapsed(true);
blc.setSouthWidget(validationView, southData);
blc.collapse(LayoutRegion.SOUTH);
sc.add(blc);
return sc.asWidget();
}
Thank you for your help.
The issue solves itself after I rewrote my code. Here is my final code, but I don't think it has really changed... Don't really understand what happened...
private Widget getContainer() {
SimpleContainer sc = new SimpleContainer();
BorderLayoutContainer blc = new BorderLayoutContainer();
ContentPanel validationView = new ContentPanel();
validationView.setHeadingText("Validation");
ContentPanel center = new ContentPanel();
center.setHeaderVisible(false);
center.add(editorMVP.getDisplay());
blc.setCenterWidget(center);
BorderLayoutData southData = new BorderLayoutData(250);
southData.setCollapsible(true);
southData.setSplit(false);
southData.setCollapsed(true);
blc.setSouthWidget(validationView, southData);
blc.collapse(LayoutRegion.SOUTH);
sc.add(blc);
return sc.asWidget();
}
My environment is: GWTP 0.7, GWT 2.4.0, GXT 3.0.1. This question is somehow related to GXT 3 grid scrolling issue but with the exception that the solution there does not work for me.
My case:
public abstract class AbstractGridView extends ViewImpl implements AbstractGridPresenter.MyView {
protected final VerticalLayoutContainer cont = new VerticalLayoutContainer();
protected final VerticalLayoutData toolBarData = new VerticalLayoutData(1, -1);
protected final VerticalLayoutData contentData = new VerticalLayoutData(1, -1); //grid's layout config
protected final ToolBar toolBar = new ToolBar();
protected final TextButton addItemButton = new TextButton(ADDBUTTON_TEXT);
#Inject
protected AbstractGridView() {
toolBar.add(addItemButton);
cont.add(toolBar, toolBarData);
}
public Widget asWidget() {
return cont;
}
}
public class DepartmentsView extends AbstractGridView implements DepartmentsPresenter.MyView {
private final Grid<Department> grid;
private final ColumnModel<Department> model;
private final List<ColumnConfig<Department, ?>> config = new ArrayList<ColumnConfig<Department,?>>();
private final ListStore<Department> store = new ListStore<Department>(PROPS.key());
#Inject
public DepartmentsView() {
super();
config.add(new ColumnConfig<Department, Long>(PROPS.id()));
config.get(config.size() - 1).setHeader(IDCOLUMN_HEADER);
config.add(new ColumnConfig<Department, String>(PROPS.name()));
config.get(config.size() - 1).setHeader(NAMECOLUMN_HEADER);
config.add(new ColumnConfig<Department, String>(companyNameProvider));
config.get(config.size() - 1).setHeader(COMPANYCOLUMN_HEADER);
model = new ColumnModel<Department>(config);
grid = new Grid<Department>(store, model);
grid.getView().setAutoFill(true);
filters.initPlugin(grid);
filters.setLocal(true);
filters.addFilter(idFilter);
filters.addFilter(nameFilter);
filters.addFilter(companyFilter);
cont.add(grid);
}
}
All these are injected into BorderLayoutContainer in BaseView:
public class BaseView extends ViewImpl implements BasePresenter.MyView {
private final Viewport viewPort = new Viewport();
private final BorderLayoutContainer borderContainer = new BorderLayoutContainer();
private final ContentPanel west = new ContentPanel();
private final ContentPanel north = new ContentPanel();
private final ContentPanel center = new ContentPanel();
private final BorderLayoutData westData = new BorderLayoutData(200);
private final BorderLayoutData northData = new BorderLayoutData();
private final BorderLayoutData centerData = new BorderLayoutData();
#Inject
public BaseView() {
borderContainer.setBorders(true);
west.setResize(true);
center.setResize(false);
center.setHeight("auto");
north.setResize(false);
westData.setCollapsible(false);
westData.setCollapseMini(false);
westData.setMargins(new Margins(5, 5, 5, 5));
northData.setCollapsible(false);
northData.setMargins(new Margins(5));
northData.setSize(57);
centerData.setCollapsible(false);
centerData.setMargins(new Margins(5));
borderContainer.setWestWidget(west, westData);
borderContainer.setCenterWidget(center, centerData);
borderContainer.setNorthWidget(north, northData);
viewPort.add(borderContainer);
}
public Widget asWidget() {
return viewPort;
}
#Override
public void setInSlot(Object slot, Widget content) {
setMainContent(content);
}
private void setMainContent(Widget content) {
center.clear();
if (content != null) {
center.setWidget(content);
}
}
}
So, if I do not attach contentData when adding my grid to VerticalLayoutContainer (cont) it renders equally to as VerticalLayoutData(1, -1) which is: grid's height is not computed at all and it's content flows under the bottom of the page with no scrollbar to get to any row lower the bottom page border. If I set VerticalLayoutData (1, 1) as in the link at the beginning of my question I can only see grid's header and grid's content's height is computed to 0px (though it's present in the page's DOM). And only if I set height manually, for example setHeight(300) grid's height sets that quantity of pixels and vertical scrollbar is shown to get to any row in the grid's store, though one can easily understand manually setting grid's height is not of any reason solution in case of Viewport managed application window.
What have I missed in widgets config or is this a bug with any reasonable workaround for it?
I've found the layout problem:
center.setResize(false); // BaseView's constructor
That made BorderLayoutContainer's ContentPanel not to resize child widget (VerticalLayoutContainer) to fit.
How Can i position Popup at the mouse clicked position in GWT. I tried using the getX, and getY on the flextable and set the Popup to that position but that isn't working.
Quick example:
final RootLayoutPanel rootLayoutPanel = RootLayoutPanel.get();
final FocusPanel focusPanel = new FocusPanel();
/* just to make the clickable area visible */
focusPanel.getElement().getStyle().setBackgroundColor("red");
rootLayoutPanel.add(focusPanel);
final PopupPanel popupPanel = new PopupPanel();
popupPanel.add(new Label("Popup"));
popupPanel.show();
focusPanel.addClickHandler(new ClickHandler() {
#Override
public void onClick(final ClickEvent event) {
final int left = event.getClientX();
final int top = event.getClientY();
popupPanel.setPopupPosition(left, top);
}
});
Notes:
Make sure to show the PopupPanel after adding the focusPanel, otherwise it will be behind the focusPanel.
I'm using the RootLayoutPanel here, but you could also work relative to a different element (use left = event.getRelativeX(myContextElem); etc.)
If you don't want to use a FocusPanel (which has ClickHandlers), you could alternatively use a MouseDownHandler, but in that case you then need to call sinkEvents(Event.ONMOUSEDOWN).
Can we add a content panel having border layout to a panle that is having an Accordion Layout. we are trying to put our central panle as well as west panel on a panle which displays this in accordion view. But not able to do this as the data is not displaying kinldy request to suggest.
Regards
Satish
You mean this?
public class test extends Composite {
private ContentPanel accordionPanel;
private ContentPanel borderPanel;
private ContentPanel westPanel;
private ContentPanel centerPanel;
public test() {
accordionPanel = new ContentPanel();
accordionPanel.setLayout(new AccordionLayout());
borderPanel = new ContentPanel();
borderPanel.setLayout(new BorderLayout());
westPanel = new ContentPanel();
borderPanel.add(westPanel, new BorderLayoutData(LayoutRegion.WEST));
centerPanel = new ContentPanel();
borderPanel.add(centerPanel, new BorderLayoutData(LayoutRegion.CENTER));
accordionPanel.add(borderPanel);
initComponent(accordionPanel);
}
}