Tuesday 15 July 2014

java - Constant Width SashForm -


There is a SashForm with two children in my application, I want to let the left child stay in the same size when the window resized To do this I have to do the same with Excel Package Explorer and the main editor. When you change the size of the window, only the text editor resizes. However, the package explorer is still resizeable by sash.

I have the following

  sashForm.addControlListener (New ControlAdapter () {@Override try to use public void controlResized (ControlEvent e) {. Int width = sashForm.getClientArea ( ) Width; int [] weight = sashForm.getWeights (); weight [1] = width - weight [0]; sashForm.setWeights (weight);}});   

The problem is that the width of the left size decreases by 0 or it spreads too much, it looks like weight is updated before or something else.

If I define some constant [0], then it does what I want to do.

I have been able to run an example that will tell you how to solve your problem. The thing is, that SashForm instead of pixels uses the weight keeps you trust depending on the size of that in spite child must calculate the percentage who left the child's parents and the rest To the right child.

In my code example, you can specify the width of the left child and set the minimum size for the right child, such as SashForm will always show both.

  Private constant final integer MIN_WIDTH_LEFT = 100; Private fixed final integer MIN_WIDTH_RIGHT = 50; Public static zero main (string [] args) {display display = new display (); Last Shell Shell = New Shell (Display); Shell.setText ("StackOverflow"); Shell.setLayout (new FillLayout ()); Last sashform form = new sashform (shell, SWT.HORIZONTAL); Button button = new button (form, SWT.PUSH); Button.setText ("left"); Button Button R = New Button (Form, SWT.PUSH); ButtonR.setText ("OK"); Form.setWeights (new int [] {1, 2}); shell.addListener (SWT.Resize, new Listener () {@Override public void handleEvent (Event arg0) {int width = shell.getClientArea () width ;. int [] weight = form.getWeights (); if (width & gt ; = MIN_WIDTH_LEFT + MIN_WIDTH_RIGHT) {weight [0] = 1000000 * MIN_WIDTH_LEFT / width, weight [1] = 1000000 - weight [0];} else {weight [0] = 1000000 * MIN_WIDTH_LEFT / (MIN_WIDTH_LEFT + MIN_WIDTH_RIGHT); weight [ 1] = 1000000 * MIN_WIDTH_RIGHT / (MIN_WIDTH_LEFT + MIN_WIDTH_RIGHT);} System.out.println (width + "+ Arrays.toString (weight)); form.setWeights (weight);}}); shell.pack (); shell Ksetsijh (600, 400); shell.open (); while (! Shell.isDisposed ()) {if (! Display.readAndDispatch ()) display.sleep ();} Display.dispose ();}   

It looks like this:

Startup:

 Enter image details here

After resizing:

 Enter image details here

When the window size decreases, it is too small to show the minimum size:

< Img src = "https: / /i.stack.imgur.com/GbZ5x.png" alt = "Enter image details here">

As you can see in this case, the left child The minimum size is still ignored to be enabled for both children to show.

No comments:

Post a Comment