Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

ScrolledComposite issue

 
Jack clouseau
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,


can anybody run this sample code below...and let me know why am not getting the scroll bars for the scrolledcomposite...

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;


public class ScrolledCompTest extends org.eclipse.swt.widgets.Composite {

public static void main(String[] args) {
showGUI();
}

protected void checkSubclass() {
}

public static void showGUI() {
Display display = Display.getDefault();
Shell shell = new Shell(display);
ScrolledCompTest inst = new ScrolledCompTest(shell, SWT.NULL);
Point size = inst.getSize();
shell.setLayout(new FillLayout());
shell.layout();
if(size.x == 0 && size.y == 0) {
inst.pack();
shell.pack();
} else {
Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
shell.setSize(shellBounds.width, shellBounds.height);
}
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}

public ScrolledCompTest(org.eclipse.swt.widgets.Composite parent, int style) {
super(parent, style);
initGUI();
}

private void initGUI() {
try {
GridLayout thisLayout = new GridLayout();
this.setLayout(thisLayout);
this.layout();

final ScrolledComposite scrollComposite = new ScrolledComposite(this, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
GridLayout scrolCompLyt = new GridLayout(1, false);
GridData scrolCompLytData = new GridData();
scrolCompLytData.widthHint = 230;
scrolCompLytData.heightHint = 200;
scrollComposite.setLayout(scrolCompLyt);
scrollComposite.setLayoutData(scrolCompLytData);

final Composite comp = new Composite(scrollComposite, SWT.NONE);
GridLayout compLyt = new GridLayout(2, false);
GridData compLytData = new GridData();
compLytData.widthHint = 300;
compLytData.heightHint = 200;
comp.setLayout(compLyt);
comp.setLayoutData(compLytData);

Label l = new Label(comp, SWT.BORDER);
l.setText("this is sample lable");
GridData ldata = new GridData();
ldata.widthHint = 200;
l.setLayoutData(ldata);

Text t = new Text(comp, SWT.BORDER);
t.setText("hello");
GridData tdata = new GridData();
tdata.widthHint = 100;
t.setLayoutData(tdata);

scrollComposite.setContent(comp);
scrollComposite.setExpandVertical(true);
scrollComposite.setExpandHorizontal(true);

} catch (Exception e) {
e.printStackTrace();
}
}

}


Am expecting the horizontasl scrollbar to show up as you can see the textfield which has the text "Hello" is not completely visible in the UI...and when i reduce the size of this window, still the scrollbars are not shown up....can anybody tell me where am going wrong???

please help me to get this done...

Thanks,
 
Jack clouseau
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
AllRight.....

Guys i found out the problem where i was doing wrong...it was the layout issue. For the control on which we are going to draw the ScrolledComposite should have a "FillLayout"..this way it works...

You guys can check the modified below code which works exactly as expected...

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class ScrolledCompTest extends org.eclipse.swt.widgets.Composite {

/**
* Auto-generated main method to display this
* org.eclipse.swt.widgets.Composite inside a new Shell.
*/
public static void main(String[] args) {
showGUI();
}

/**
* Overriding checkSubclass allows this class to extend org.eclipse.swt.widgets.Composite
*/
protected void checkSubclass() {
}

/**
* Auto-generated method to display this
* org.eclipse.swt.widgets.Composite inside a new Shell.
*/
public static void showGUI() {
Display display = Display.getDefault();
Shell shell = new Shell(display);
ScrolledCompTest inst = new ScrolledCompTest(shell, SWT.NULL);
Point size = inst.getSize();
shell.setLayout(new FillLayout());
shell.layout();
if(size.x == 0 && size.y == 0) {
inst.pack();
shell.pack();
} else {
Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
shell.setSize(shellBounds.width, shellBounds.height);
}
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}

public ScrolledCompTest(org.eclipse.swt.widgets.Composite parent, int style) {
super(parent, style);
initGUI();
}

private void initGUI() {
try {
FillLayout thisLayout = new FillLayout();
this.setLayout(thisLayout);
this.layout();

final ScrolledComposite scrollComposite = new ScrolledComposite(this, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
final Composite comp = new Composite(scrollComposite, SWT.NONE);
GridLayout compLyt = new GridLayout(2, false);
comp.setLayout(compLyt);

Label l = new Label(comp, SWT.BORDER);
l.setText("this is sample lable");
GridData lData = new GridData();
lData.widthHint = 200;
l.setLayoutData(lData);

Text t = new Text(comp, SWT.BORDER);
t.setText("hello");
GridData tData = new GridData();
tData.widthHint = 100;
t.setLayoutData(tData);

scrollComposite.setContent(comp);
scrollComposite.setExpandVertical(true);
scrollComposite.setExpandHorizontal(true);
scrollComposite.setMinSize(comp.computeSize(SWT.DEFAULT, SWT.DEFAULT));

} catch (Exception e) {
e.printStackTrace();
}
}

}

Anyways thanks to all the guys...who atleast gave a try on this...

cheers,
 
Rob Spoor
Sheriff
Pie
Posts: 20529
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please UseCodeTags next time? That will make your code more readable.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic