SWT Splitter problem

C

crazychrisy54

Hi there

I have used a splitter in my GUI however after using it to reduce the
size of one component, thus increasing the size of the other, when I
then try to resize the whole window (top level shell attached to a
display) the functionality is lost: the components will not be scaled
down in relation to each other. I would be much appreciated if anyone
had any ideas how about I can fix this problem.

A simpler example found on the internet that has the same problem is
this
http://www.java2s.com/Code/Java/SWT-JFace-Eclipse/Implementasimplesplitterwitha20pixellimit.htm
It will resize fine before moving the splitter, but after moving the
splitter about the window resizability does not function correctly.

My code to perform this splitting is displayed below:

public class Splitter extends Composite{

public Splitter(Composite parent, Control ctrlA, Control ctrlB, int
splitDirection){
super(parent,SWT.NONE);

setLocation(0,0);
setSize(parent.getSize());
setVisible(true);
boolean result = ctrlA.setParent(this);
assert result;
result = ctrlB.setParent(this);
assert result;

final Sash sash = new Sash(this, splitDirection);
final FormLayout form = new FormLayout();
setLayout(form);

FormData ctrlAFormData = new FormData();
ctrlAFormData.left = new FormAttachment(0, 0);
ctrlAFormData.top = new FormAttachment(0, 0);


if(splitDirection == SWT.VERTICAL){
ctrlAFormData.right = new FormAttachment(sash, 0);
ctrlAFormData.bottom = new FormAttachment(100, 0);
}
else if(splitDirection == SWT.HORIZONTAL){
ctrlAFormData.right = new FormAttachment(100, 0);
ctrlAFormData.bottom = new FormAttachment(sash, 0);
}

ctrlA.setLayoutData(ctrlAFormData);

final int limit = 20;
final FormData sashData = new FormData();

if(splitDirection == SWT.VERTICAL){
//sashData.width = 10;
final int percent = 30;
sashData.left = new FormAttachment(percent, 0);
sashData.top = new FormAttachment(0, 0);
sashData.bottom = new FormAttachment(100, 0);
sash.setLayoutData(sashData);

sash.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
Rectangle sashRect = sash.getBounds();
Rectangle shellRect = sash.getParent().getClientArea();
int right = shellRect.width - sashRect.width - limit;
e.x = Math.max(Math.min(e.x, right), limit);
if (e.x != sashRect.x) {
sashData.left = new FormAttachment(0, e.x);
sash.getParent().layout();
}
}
});
}
else if(splitDirection == SWT.HORIZONTAL){
//sashData.width = 10;
final int percent = 70;
sashData.left = new FormAttachment(0, 0);
sashData.top = new FormAttachment(percent, 0);
sashData.right = new FormAttachment(100, 0);
sash.setLayoutData(sashData);

sash.addListener(SWT.Selection, new Listener() {
public void handleEvent(Event e) {
Rectangle sashRect = sash.getBounds();
Rectangle shellRect = sash.getParent().getClientArea();
//Rectangle shellRect = getClientArea();
int right = shellRect.height - sashRect.height - limit;
e.y = Math.max(Math.min(e.y, right), limit);
if (e.y != sashRect.y) {
sashData.top = new FormAttachment(0, e.y);
sash.getParent().layout();
}
}
});
}


FormData ctrlBFormData = new FormData();
ctrlBFormData.right = new FormAttachment(100, 0);
ctrlBFormData.bottom = new FormAttachment(100, 0);
if(splitDirection == SWT.VERTICAL){
ctrlBFormData.left = new FormAttachment(sash, 0);
ctrlBFormData.top = new FormAttachment(0, 0);
}
else if(splitDirection == SWT.HORIZONTAL){
ctrlBFormData.left = new FormAttachment(0, 0);
ctrlBFormData.top = new FormAttachment(sash, 0);
}
ctrlB.setLayoutData(ctrlBFormData);

layout();
}

}

My main program uses this:
Splitter splitterVertical = new Splitter(shell, hierarchyTree,
sourceTree, SWT.VERTICAL);
Splitter splitterHorizonal = new Splitter(shell, splitterVertical,
messageTable, SWT.HORIZONTAL);
hierachyTree and sourceTree are of type swt.widgets.Tree;
messageTable is of type swt.widgets.Table;

Thanks in advance!
Chris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top