Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SashForm children width
SashForm children width [message #648333] Wed, 12 January 2011 13:37 Go to next message
Michael  is currently offline Michael
Messages: 4
Registered: October 2010
Junior Member
Hi,

I've got an horizontal SashForm with two children. The one on the left should always be, at least, 200 pixels width.
I've disallowed dragging the sash below 200px, but the problem comes when the shell is resized. I've added a ControlListener to the left component. In its controlResized event I check the component width. When it's smaller than 200, I set its bounds' width to 200. It apparently works as the component gets resized to that width, but the sashform stops working - the sash is no longer visible, it remains under the component.

Does anybody know what am I missing?

Thanks in advance
Re: SashForm children width [message #648498 is a reply to message #648333] Thu, 13 January 2011 09:16 Go to previous messageGo to next message
Lakshmi Shanmugam
Messages: 274
Registered: July 2009
Location: India
Senior Member
Hi,

SashForm manages the position and size of its children automatically based on the weights you set.
I think the problem you are seeing may be because you are trying to set the bounds of the components directly. Instead you could recompute and reset the weights in the controlResized event.
The example in this thread may be useful --> http://www.eclipse.org/forums/index.php?t=msg&th=198780& amp; amp;start=0&S=3348500362cdfe2a528b4cce8c01f18f

HTH,
Lakshmi


Lakshmi P Shanmugam

[Updated on: Thu, 13 January 2011 09:17]

Report message to a moderator

Re: SashForm children width [message #648537 is a reply to message #648333] Thu, 13 January 2011 13:00 Go to previous messageGo to next message
Michael  is currently offline Michael
Messages: 4
Registered: October 2010
Junior Member
Thanks for your reply, Lakshmi

I preferred not to touch weights, because I would like the sashform to maintain the original user aspect ratio if he enlarged the window again, so the components looked the same as before. But anyway, I gave it a try without success. Here's my fragment using your snippet:

leftComponent.addControlListener(new ControlAdapter() {
	public void controlResized(ControlEvent event) {
		if (leftComponent.getBounds().width < 200) {
			int totalWidth = sashForm.getClientArea().width;
			sashForm.setWeights(new int[] {200, totalWidth - 200});
		}
	}
});


But the effect is the same: no visible sash. What's wrong with my code?

Thanks
Re: SashForm children width [message #649067 is a reply to message #648537] Mon, 17 January 2011 13:37 Go to previous messageGo to next message
Lakshmi Shanmugam
Messages: 274
Registered: July 2009
Location: India
Senior Member
Hi,

Which platform are you using? Can you paste an example snippet showing your problem?


Lakshmi P Shanmugam
Re: SashForm children width [message #649987 is a reply to message #648333] Fri, 21 January 2011 10:07 Go to previous messageGo to next message
Michael  is currently offline Michael
Messages: 4
Registered: October 2010
Junior Member
Quote:
Which platform are you using? Can you paste an example snippet showing your problem?


I'm using Linux/GTK, although this should work on other platforms (win32 and macosx). Here's the snippet:

public class SashExample {
	
	public static void main(String[] args) {
		
		final int MIN_SIZE = 150;
		
		Display display = new Display();
		Shell shell = new Shell(display);
		
		shell.setLayout(new FillLayout());
		
		final SashForm sashForm = new SashForm(shell, SWT.NONE);
		
		final Composite left = new Composite(sashForm, SWT.BORDER);
		final Composite right = new Composite(sashForm, SWT.BORDER);
		
		left.setLayout(new RowLayout());
		right.setLayout(new RowLayout());
		
		new Label(left, SWT.NONE).setText("Left side");
		new Label(right, SWT.NONE).setText("Right side");
		
		left.addControlListener(new ControlAdapter() {
			public void controlResized(ControlEvent event) {
				if (left.getBounds().width < MIN_SIZE) {
					int totalWidth = sashForm.getClientArea().width;
					sashForm.setWeights(new int[] {MIN_SIZE, totalWidth - MIN_SIZE});
				}
			}
		});
		
		sashForm.setWeights(new int [] {1, 3});
		
		shell.setSize(1000, 600);
		shell.open();
		
		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
		
		display.dispose();
		
	}

}


Thanks!
Re: SashForm children width [message #650018 is a reply to message #649987] Fri, 21 January 2011 13:33 Go to previous message
Lakshmi Shanmugam
Messages: 274
Registered: July 2009
Location: India
Senior Member
Hi,
The same workaround/fix suggested in the other thread ( http://www.eclipse.org/forums/index.php?t=msg&th=198780& amp;start=0&S=3348500362cdfe2a528b4cce8c01f18f) should work for your example too.
Call sashform.layout() inside display.asyncExec() after resetting the weights in the control listener.


Lakshmi P Shanmugam
Previous Topic:Hyperlinks in tree node text?
Next Topic:Accelerator key for a widget placed before a label?
Goto Forum:
  


Current Time: Wed Oct 22 22:31:58 GMT 2014

Powered by FUDForum. Page generated in 0.03177 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software