java - Update parent size -
I have a function that should update the size of all the parents of a overall
When children are added to do this, but this is not working here, my code is:
Private zero growth size (composite child, overall parent) {parent.layout () ; Rectangle child's post = child Bats (); Rectangle parentPosition = parent.getBounds (); Int parentY = parent.to Display (parentPosition.width, parentPosition.height) .y; Initiative = Children Display (childposition.width, childposition.height) .y; If (childY> parentY) {int heightDifference = childY - parentY; Parent.setSize (parentPosition.width, parentPosition.height + heightDefence + 5); System.out.println ("guardian y:" + parentY + ", child y:" + childY); } And {return; } Parent.layout (); Parent.setVisible (true); If (! (Original example shell)) increase (size, parent, parent.getParent ()); }}
If I extract the line in if
-statement ( (parent, parent.getParent ());
)
more code main:
public class exam {/ p> public static zero main (string [] args) { Display display = new display (); Shell shell = new shell (display); Shell.setLayout (new FillLayout (SWT.VERTICAL)); Shell.setSize (200,100); Button button = new button (shell, SWT.PUSH); Button.setText ("Click here to add composite"); Grid data selectiondata = new grid data (SWT.FILL, SWT.FILL, true, true); Final Custom Compose Selection = New Custom Composite (Shell, SWT.BORDER, Selection Data); button. Add selector () {@ Overheaded SelectionEvent selectionEvent} {selection.add ("I have been added");} @ Override Public Wide Widgets Default Selection (SelectionEvent selectionEvent) {}}); Shell.open (); While (! Shell.isDisposed ()) {if (! Display.readAndDispatch ()) display.sleep (); } Display.dispose (); }
}
} CustomComposite:
public class CustomComposite Composite {Private GridData layoutData; Public CustomComposite (composite parent, int style, gridata layout data) {super (guardian, style); Setout (new rollout ()); SetLayoutData (layoutData); LayoutData.exclude = true; This.layoutData = layoutData; } Add Public Zero Add Chosen (String Display Name) {Selected Composite Items = New Selected Composite (SWT.BORDER, displayName); If (layoutData.exclude == true) {layoutData.exclude = false; GetParent () layout () .; } Increase size (item, this); GetShell () Layout (true, true); } Private zero growth size (composite child, holistic parent) {parent.layout (); Rectangle child's post = child Bats (); Rectangle parentPosition = parent.getBounds (); Int parentY = parent.to Display (parentPosition.width, parentPosition.height) .y; Initiative = Children Display (childposition.width, childposition.height) .y; If (childY> parentY) {int heightDifference = childY - parentY; Parent.setSize (parentPosition.width, parentPosition.height + heightDefence + 5); } And {return; } Parent.setVisible (true); If (! (Original example shell)) increase (size, parent, parent.getParent ()); }} Selected class composite {Private label label = new label (this, SWT.NONE) is expanded; Public chosen composite (composite parent, int style, string display name) {super (original, genre); SetLayout (new FillLayout ()); Label.setText (DISPLAYNAME); }}
}
Comments
Post a Comment