Like Need GWT SplitLayoutPanel to have max size, dragging is very jumpy I am wondering why the right and the southern splitters jump (tested in IE9; both, web and hosted mode) when trying to drag the splitters in the following example:
public class SplitLayoutPanelTest implements EntryPoint {
public void onModuleLoad() {
final SplitLayoutPanel p = new SplitLayoutPanel(5);
p.setSize(Window.getClientWidth()+"px", Window.getClientHeight()+"px");
final Frame fWest = new Frame("http://bsd.org");
fWest.setSize("400px", "200px");
p.insertWest(fWest, 400, null);
final Frame fEast = new Frame("http://www.linux.org");
fEast.setSize("90px", "90px");
p.insertEast(fEast, 100, null);
final Frame fNorth = new Frame("http://www.w3c.org");
fNorth.setSize("80px", "80px");
p.insertNorth(fNorth, 100, null);
final Frame fSouth = new Frame("http://www.sqlite.org");
fSouth.setSize("85px", "85px");
p.insertSouth(fSouth, 100, null);
final Frame fCenter = new Frame("http://www.gnu.org");
fCenter.setSize("75px", "75px");
p.insert(fCenter, Direction.CENTER, 200, null);
RootPanel.get().add(p);
}
}
Any ideas?
Take a look at this answer in
Need GWT SplitLayoutPanel to have max size, dragging is very jumpy
I hope this solves your issue as well, good luck
So here is one possible solution:
public class SplitLayoutPanelTest implements EntryPoint {
public void onModuleLoad() {
final SplitLayoutPanel p = new SplitLayoutPanel(5);
p.setSize(Window.getClientWidth()+"px", Window.getClientHeight()+"px");
final Frame fWest = new Frame("http://bsd.org");
final VerticalPanel pWest = new VerticalPanel();
pWest.setSize("100%", "100%");
pWest.add(fWest);
p.insertWest(pWest, 400, null);
fWest.setSize("400px", "200px");
final Frame fEast = new Frame("http://www.linux.org");
final VerticalPanel pEast = new VerticalPanel();
pEast.setSize("100%", "100%");
pEast.add(fEast);
p.insertEast(pEast, 100, null);
fEast.setSize("90px", "90px");
final Frame fNorth = new Frame("http://www.w3c.org");
final VerticalPanel pNorth = new VerticalPanel();
pNorth.setSize("100%", "100%");
pNorth.add(fNorth);
p.insertNorth(pNorth, 100, null);
fNorth.setSize("80px", "80px");
final Frame fSouth = new Frame("http://www.sqlite.org");
final VerticalPanel pSouth = new VerticalPanel();
pSouth.setSize("100%", "100%");
pSouth.add(fSouth);
p.insertSouth(pSouth, 100, null);
fSouth.setSize("85px", "85px");
final Frame fCenter = new Frame("http://www.gnu.org");
final VerticalPanel pCenter = new VerticalPanel();
pCenter.setSize("100%", "100%");
pCenter.add(fCenter);
p.insert(pCenter, Direction.CENTER, 200, null);
fCenter.setSize("75px", "75px");
RootPanel.get().add(p);
}
}
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);
Im trying to create a little Telnet Client for a MUD. In this program i want to have a scrollable map. I already made this and it works pretty good. But as soon as i reach the borders it deletes the rectangles (painted with GC) outside the window. If i go back to them, the shapes are not there anymore.
Little Gif to show the problem:
https://gifyu.com/image/vhnq
Im scrolling with the the ScrolledComposite.setOrigin(Point p) function inside an async Runnable.
Canvas declaration + parents (room is an int with value 10):
Composite container = new Composite(mapShell, SWT.FILL);
container.setLayout(new GridLayout(2, false));
scrolledComposite = new ScrolledComposite(container, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
scrolledComposite.setVisible(true);
scrolledComposite.setAlwaysShowScrollBars(false);
scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, true, 1, 4));
int width = 10000, height = 10000;
Canvas mapCanvas = new Canvas(scrolledComposite, SWT.NONE);
mapCanvas.setBackground(mapShell.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY));
mapCanvas.setSize(width, height);
mapCanvas.setLocation(0, 0);
final ScrollBar hBar = scrolledComposite.getHorizontalBar();
final ScrollBar vBar = scrolledComposite.getVerticalBar();
hBar.setIncrement(room * 2);
vBar.setIncrement(room * 2);
gc = new GC(mapCanvas);
mapCanvas.setLayout(null);
scrolledComposite.setContent(mapCanvas);
scrolledComposite.setMinSize(new Point(300, 400));
Function to draw the rooms:
public void changeCurrentRoom(Room newRoom) {
mapShell.getDisplay().asyncExec(new Runnable() {
#Override
public void run() {
gc.setBackground(currentRoom.getColor());
gc.fillRectangle(currentRoom.getRectangle());
currentRoom = newRoom;
gc.setBackground(ACTIVE_ROOM_COLOR);
gc.fillRectangle(currentRoom.getRectangle());
}
});
mapShell.getDisplay().asyncExec(new Runnable() {
#Override
public void run() {
scrolledComposite.setOrigin(getScrollPosition(currentRoom));
roomText.setText(currentRoom.getName());
}
});
}
Thanks for your help!
When i run the following Code and push Button "Push", more than once a time, i get browser error "simplePanel can only contain one child widget". How can i solve that problem? thank you in advance! Jogi
public class Projekt implements EntryPoint {
private RootPanel rootPanel;
public void onModuleLoad() {
rootPanel = RootPanel.get("gwtContainer");
rootPanel.setSize("1902", "868");
final AbsolutePanel boundaryPanel = new AbsolutePanel();
boundaryPanel.setStyleName("frame1");
boundaryPanel.setSize("1455px", "600px");
final Diagram diagram = new Diagram(boundaryPanel);
RootPanel.get().add(boundaryPanel, 446, 242);
final Connector con = new Connector(100, 300, 300, 500);
Button la = new Button("Push");
la.setSize("200", "200");
RootPanel.get().add(la);
Button la2 = new Button("Push2");
la2.setSize("200", "200");
RootPanel.get().add(la2);
final Image img = new Image("images/concrete.svg");
img.setSize("200", "200");
final Shape shapei = new Shape(img);
Image img2 = new Image("images/variable.svg");
img2.setSize("200", "200");
boundaryPanel.add(img2, 200,200);
final Shape shapei2 = new Shape(img2);
shapei2.showOnDiagram(diagram);
la.addClickHandler(new ClickHandler(){
#Override
public void onClick(ClickEvent event) {
boundaryPanel.add(img, 100,100);
shapei.showOnDiagram(diagram);
}
});
la2.addClickHandler(new ClickHandler(){
#Override
public void onClick(ClickEvent event) {
con.showOnDiagram(diagram);
}
});
diagram.addDiagramListener(new DiagramListenerAdapter() {
#Override
public void onElementConnect(ElementConnectEvent event) {
if (con.startEndPoint.isGluedToConnectionPoint()) {
Widget connected = con.startEndPoint.gluedConnectionPoint.parentWidget;
if(connected.equals(shapei.connectedWidget)){
Image logo = new Image("images/xor.svg");
logo.setSize("100", "100");
boundaryPanel.add(logo);
}
else if(connected.equals(shapei2.connectedWidget)){
Image logo2 = new Image("images/and.svg");
logo2.setSize("100", "100");
boundaryPanel.add(logo2);
};
}}
});
}}
RootPanel.get() is a SimplePanel. You try to add more than one child to it, resulting in this error.
Instead, you should add HTMLPanel, for example, to your RootPanel, and then add all the children to this HTMLPanel.
I suppose your Diagram extends GWT's SimplePanel
class? SimplePanel can contain only a single widget, have a look here:
http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/client/ui/SimplePanel.html
You could either extend a different class, or call the remove(Widget w) method to remove the existing widget before trying to add a new one.
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.
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.