gwt splitlayout insert widgets to layout - gwt

I've created the splitlayout and created a new ListBox.
ListBox lb = new ListBox();
lb.addItem("foo");
lb.addItem("bar");
lb.addItem("baz");
lb.addItem("toto");
lb.addItem("tintin");
SplitLayoutPanel p = new SplitLayoutPanel();
p.addWest(new HTML("list"), 128);
p.add(new HTML("details"));
RootLayoutPanel rp = RootLayoutPanel.get();
rp.add(p);
Now how do i insert 'lb' to the west of 'p' ?
I tried 'p.addWest(lb,pixel);' instead of 'p.addWest(new HTML("list"), 128);' it looks and behaves terrible !! Please help

ListBox lb = new ListBox();
lb.addItem("foo");
lb.addItem("bar");
lb.addItem("baz");
lb.addItem("toto");
lb.addItem("tintin");
SplitLayoutPanel p = new SplitLayoutPanel();
p.addWest(lb, 100);
p.addWest(new HTML("list"), 128);
p.add(new HTML("details"));
RootLayoutPanel rp = RootLayoutPanel.get();
rp.add(p);
In SplitLayoutPanel/DockLayoutPanel you cannot add widgets after you add your center widget i.e., after you use the api splitLayoutPanel.add( Widget w ), So you have to do all the operations before hand or re layout the entire panel by clearing it first.

Related

Hiding SWT Controls

How we can hide the SWT controls?
I know setVisible() method of control class can be used. But the disadvantage of it is, hidden widget will not released and can't be used by other widgets.
Is there any other approach which can be adopted?
You can use layout data. In case of GridLayout, you can use exclude specific widget from being drown on canvas.
Composite comp = new Composite(shell, SWT.NONE);
comp.setLayout(new GridLayout(4, false));
Label hidenLabel = new Label (comp, SWT.NONE);
GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
hidenLabel.setGridData(gridData );
//hide the button
gridData .exclude = true;
comp.pack();

Use FillLayout with Browser in SWT

I have a view that consists of a heading and a browser. I want the browser to fill my view. This is how it should look:
I have tried out different combinations.
c = new Composite(parent, SWT.NONE);
c.setLayout(new RowLayout(SWT.VERTICAL));
Label l = new Label(c, SWT.NONE);
l.setBackground(color);
l.setText("----------------------Heading--------------------------------");
l.setFont(new Font(null, new FontData(Constants.FONT, 12, SWT.BOLD)));
Composite wrapper = new Composite(c, SWT.NONE);
wrapper.setBackground(new Color(null, 0, 0, 0));
wrapper.setLayout(new FillLayout(SWT.VERTICAL));
browser = new Browser(wrapper, SWT.WRAP);
browser.setBackground(color);
produces:
Setting a FillLayout to c does not work either. By doing so both, heading and browser, share the view's size and have an equal size.
c = new Composite(parent, SWT.NONE);
c.setLayout(new FillLayout(SWT.VERTICAL));
Label l = new Label(c, SWT.NONE);
l.setBackground(color);
l.setText("----------------------Heading--------------------------------");
l.setFont(new Font(null, new FontData(Constants.FONT, 12, SWT.BOLD)));
browser = new Browser(c, SWT.WRAP);
browser.setBackground(color);
produces:
I have also tried the following:
composite with filllayout
-> composite with gridlayout
->composite with rowLayout (fixed height, grab right)
->composite with rowLayout
-> composite with fillLayout
-> composite with browser
Assuming that the header and browser have the same parent, you could use a GridLayout like this:
parent.setLayout( new GridLayout( 1, false ) );
label.setLayoutData( new GridData( SWT.FILL, SWT.TOP, true, false ) );
browser.setLayoutData( new GridData( SWT.FILL, SWT.FILL, true, true ) );
Even though a one-cell-grid isn't really what a GridLayout is meant for, it should do the trick. The layout data advise the label to align at the top and use all horizontal space and the browser to use the horizontal and vertical space

GWT htmlDialogBox: How to set the size to wider width

I want to resize my htmlDialogBox to wider width. This is what I have now. Half of my html is cut off. I want to display the entire html in the htmlDialogBox.
GWT version: 2.8.0-SNAPSHOT
verticalPanel = new VerticalPanel();
verticalPanel.setSpacing(0);
setWidget(verticalPanel);
verticalPanel.setSize("100%","100%");
scrollPanel = new ScrollPanel();
verticalPanel.add(scrollPanel);
htmlDialogBox = new HTML();
verticalPanel.add(htmlDialogBox);
scrollPanel.setWidget(htmlDialogBox);
htmlDialogBox.setSize("100%", "100%");
htmlDialogBox.setHTML(html);
setGlassEnabled(true);
setAnimationEnabled(true);
setPopupPosition(ClientUtils.DIALOG_X_POSITION,ClientUtils.DIALOG_Y_POSITION);
show();
I find my own answer.
change setAnimationEnabled(true); to setAnimationEnabled(false);

Horizontal center a FlexTable in a parent FlowPanel?

I've created a FlexTable, and I want to center it horizontally within a parent FlowPanel, like:
FlexTable ft = new FlexTable();
ft.add(0, 0, new Label());
ft.add(0, 1, new Orange());
ft.add(0, 2, new Label());
FlowPanel parent = new FlowPanel();
parent.add(ft); // how can I horizontally center the table in this div?
The content of the table is narrower than the parent FlowPanel (which is width:auto, the whole width of the browser), but the table is left-aligned right now,
Thanks
Two options:
parent.getElement().getStyle().setTextAlign(TextAlign.CENTER);
or
ft.getElement().getStyle().setProperty("margin", "0 auto");
You can use CSS styles instead, of course.
First of all? Which version of GWT are you using? The reason am asking this question, there is no method in FlexTable that is similar to add (int, int, Widget ) you have used in the latest version.
However, you can use the following code.
FlexTable ft = new FlexTable();
ft.setWidget(0, 0, new Label("a"));
ft.setWidget(0, 1, new Label("b"));
ft.setWidget(0, 2, new Label("c"));
FlowPanel parent = new FlowPanel();
parent.setSize("100%", "100%");
parent.add(ft);
parent.getElement().getStyle().setProperty("TextAlign", "center");
// If you are using Firefox :
//parent.getElement().getStyle().setProperty("TextAlign", "-moz-center");
RootLayoutPanel.get().add(parent);
If you dont't wish to mention the style in the java code, you can always use CSS like
parent.addStyleName("myStyle");
In CSS
.myStyle{
text-align : center;
}

horizontalSpan in SWT GridLayout doesn't span

I'm trying to configure a dialog window like so:
#Override
protected Control createDialogArea(Composite parent) {
GridLayout dialogAreaLayout = new GridLayout();
dialogAreaLayout.numColumns = 2;
parent.setLayout(dialogAreaLayout);
GridData gridData = new GridData();
gridData.grabExcessHorizontalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
gridData.minimumWidth = 300;
// the label in the first row should span across both columns
gridData.horizontalSpan = 2;
Label headlineLabel = new Label(parent, SWT.NONE);
headlineLabel.setText("example test");
headlineLabel.setLayoutData(gridData);
// the rest should be ordered in two columns
gridData.horizontalSpan = 1;
companyLabel = new Label(parent, SWT.NONE);
companyLabel("company");
companyTextfield = new Text(parent, SWT.BORDER);
companyTextfield(gridData);
...
What I'm trying to accomplish is a label in the first line, that spans across both columns and have the following fields be ordered in pairs per line. What I get with this is, that the lable (that should be left in second line) is right in first line, just as the label wouldn't span across two columns. Can anybody see, what I'm doing wrong?
Thanx again!
After setting the layoutData to headlineLabel, you are setting the horizontalSpan to 1. You need to create a new LayoutData object for every SWT widget. It is not possible to reuse them after setting them.