File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes ScrolledComposite issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "ScrolledComposite issue" Watch "ScrolledComposite issue" New topic
Author

ScrolledComposite issue

Jack clouseau
Greenhorn

Joined: May 14, 2008
Posts: 22
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,

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea!!!
Jack clouseau
Greenhorn

Joined: May 14, 2008
Posts: 22
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

Joined: Oct 27, 2005
Posts: 19760
    
  20

Could you please UseCodeTags next time? That will make your code more readable.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ScrolledComposite issue