graphic context鏄湪GC綾諱腑鐨勶紝GC瀵硅薄鏄檮鐫浜庣幇瀛樼殑Controls銆?br /> 瑕佸垱寤轟竴涓猤raphically oriented鐨勫簲鐢ㄧ▼搴忥紝棣栧厛瑕佸垱寤篻raphic context錛屽茍灝嗗叾涓庝竴涓猚omponent鐩稿叧鑱旓紝榪欎袱姝ラ兘鍙氳繃GC鐨刢onstructor鏉ュ疄鐜般傚叡鏈?涓瀯閫犲嚱鏁幫紝瑙佷笅錛?br />1. GC(Drawable)--Creates a GC and configures it for the Drawable object 2. GC(Drawable, int)--Creates and configures a GC and sets the text-display style錛岀浜屼釜鍙傛暟鍙互鏄疪IGHT_TO_LEFT鎴朙EFT_TO_RIGHT錛堥粯璁ゅ鹼級; 絎竴涓弬鏁伴渶瑕佸疄鐜癉rawable鎺ュ彛鐨勫璞★紝 姝ゆ帴鍙e寘鍚簡涓巊raphic context.鍐呴儴鐩歌仈緋葷殑鏂規硶銆係WT鎻愪緵浜嗕笁涓疄鐜癉rawable鎺ュ彛鐨勭被錛欼mage, Device,聽鍜?Control.
protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) { Point maxDimensions = calculateMaxDimensions(composite.getChildren()); int stepsPerHemisphere = stepsPerHemisphere(composite.getChildren().length); int maxWidth = maxDimensions.x; int maxHeight = maxDimensions.y; int dimensionMultiplier = (stepsPerHemisphere + 1); int controlWidth = maxWidth * dimensionMultiplier; int controlHeight = maxHeight * dimensionMultiplier; int diameter = Math.max(controlWidth, controlHeight); Point preferredSize = new Point(diameter, diameter); ... // code to handle case when our calculations // are too large return preferredSize; }
鍙傛暟錛?br />1.composite--The object we鈥檙e going to populate. At the time this method is called, it has children, but neither the composite nor the children have been sized or positioned on the screen.
2.wHint and hHint--layout鎵闇鐨勬渶澶ч暱瀹姐傝嫢甯︽湁鍙傛暟SWT.DEFAULT,琛ㄧず姝ayout鍙互闅忔剰浣跨敤use whatever sizes it decides it needs.
3.flushCache--浣滀負flag錛宼o tell the layout whether it鈥檚 safe to use any cached values that it may be maintaining.
]]>6.4 The form layouthttp://m.tkk7.com/joeyjong/archive/2006/04/12/40607.htmlJOOJOOWed, 12 Apr 2006 04:22:00 GMThttp://m.tkk7.com/joeyjong/archive/2006/04/12/40607.htmlhttp://m.tkk7.com/joeyjong/comments/40607.htmlhttp://m.tkk7.com/joeyjong/archive/2006/04/12/40607.html#Feedback0http://m.tkk7.com/joeyjong/comments/commentRss/40607.htmlhttp://m.tkk7.com/joeyjong/services/trackbacks/40607.html
涓庝箣鍓嶆墍榪扮殑layout涓嶅悓錛宖orm layout涓嶆槸鍩轟簬琛屽拰鍒楃殑錛屽畠鏄熀浜庝笌鍏朵粬control涔嬮棿鐨勭浉瀵逛綅緗殑銆?br /> FormLayout鍗佸垎綆鍗曪紝浣犲彧瑕侊細1.璁懼畾欏佃竟璺濓紙楂橈紝瀹斤級灞炴с?2.璁懼畾spacing灞炴э紝鍗蟲墍鏈塩ontrol闂寸殑璺濈(in pixels)
鍚屾牱鍙互浣跨敤FormData鏉ラ厤緗崟涓殑control銆?br /> FormData 濡傛灉涓涓猚ontrol娌℃湁涓涓狥ormData瀹炰緥鏉ユ弿榪板畠鐨勮瘽錛屽氨浼氶粯璁ゆ斁鍦╟omposite鐨勫彸涓婅 width鍜宧eight灞炴ф寚瀹氫簡control鐨勫昂瀵革紝in pixels. top, bottom, right, 鍜宭eft灞炴э紝姣忎竴涓兘鏈変竴涓狥ormAttachment瀹炰緥錛岃繖浜沘ttachments鎻忚堪浜哻ontrol涓庡叾浠朿ontrol涔嬮棿鐨勫叧緋匯?br /> FormAttachment 鏈?涓嬌鐢ㄩ斿緞錛?br />1.閫氳繃浣跨敤percentage of the parent composite.
2.閫氳繃璁懼畾涓涓猚ontrol鍜屽彟涓涓猚ontrol涔嬮棿鐨勭浉瀵逛綅緗?br />銆婂浘銆?br /> package com.swtjface.Ch6; import org.eclipse.swt.*; import org.eclipse.swt.widgets.*; import org.eclipse.swt.layout.*; public class Ch6FormLayoutComposite extends Composite { public Ch6FormLayoutComposite(Composite parent) { super(parent, SWT.NONE); FormLayout layout = new FormLayout(); setLayout(layout); Text t = new Text(this, SWT.MULTI); FormData data = new FormData(); data.top = new FormAttachment(0, 0); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(100); data.bottom = new FormAttachment(75);//紜畾text鐨勪綅緗紝鍥犱負宸︿笂瑙掓槸鍧愭爣鍘熺偣錛屾墍浠ight鐨勭櫨鍒嗘暟涓?00銆?br />t.setLayoutData(data); Button ok = new Button(this, SWT.NONE); ok.setText("Ok"); Button cancel = new Button(this, SWT.NONE); cancel.setText("Cancel"); data = new FormData(); data.top = new FormAttachment(t); data.right = new FormAttachment(cancel);//ok鎸夐挳鍦╰ext涓嬮潰錛宑ancel宸﹁竟 ok.setLayoutData(data); data = new FormData(); data.top = new FormAttachment(t); data.right = new FormAttachment(100);//cancel鎸夐挳鍦╰ext涓嬮潰錛屽湪鏈鍙寵竟 cancel.setLayoutData(data); } }
]]>6.3 The grid layouthttp://m.tkk7.com/joeyjong/archive/2006/04/11/40484.htmlJOOJOOTue, 11 Apr 2006 08:16:00 GMThttp://m.tkk7.com/joeyjong/archive/2006/04/11/40484.htmlhttp://m.tkk7.com/joeyjong/comments/40484.htmlhttp://m.tkk7.com/joeyjong/archive/2006/04/11/40484.html#Feedback0http://m.tkk7.com/joeyjong/comments/commentRss/40484.htmlhttp://m.tkk7.com/joeyjong/services/trackbacks/40484.html
鏈甯哥敤鐨勪竴縐峫ayout.浠ow layout涓哄熀紜銆?br /> package com.swtjface.Ch6; import org.eclipse.swt.*; import org.eclipse.swt.widgets.*; import org.eclipse.swt.layout.*; public class Ch6GridLayoutComposite extends Composite { public Ch6GridLayoutComposite(Composite parent) { super(parent, SWT.NONE); GridLayout layout = new GridLayout(4,false);//姣忎竴琛屾湁4涓猚ontrol錛屽悗涓涓弬鏁版槸a boolean to indicate whether the columns should take up an even amount of space. By passing false, you tell the layout to only use the minimum amount of space needed for each column. setLayout(layout); for (int i = 0; i < 16; ++i) { Button button = new Button(this, SWT.NONE); button.setText("Cell " + i); } } }
Using GridData styles 鍗佸垎綾諱技浜嶳owData瀵硅薄銆傚彲閫氳繃鍏舵瀯閫犲嚱鏁版潵璁懼畾STYLE錛岃繖浜汼TYLE鍙垎涓?綾伙細FILL, HORIZONTAL_ALIGN, and VERTICAL_ALIGN. 1.FILL:姝ell鏄惁fill鎵鏈夌殑availabe鐨勭┖闂淬傚彲鐢ㄧ殑鍊艱繕鍖呮嫭FILL_HORIZONTAL錛堟按騫蟲墿寮狅級,FILL_VERTICAL錛堝瀭鐩存墿寮狅級,FILL_BOTH銆?br />2.ALIGN錛岀敤鏉ユ寚瀹歝ontrol鍦╟ell涓殑浠涔堜綅緗傚煎寘鎷珺EGINNING, END, CENTER鍜孎ILL銆?br />鍏蜂綋鍙傝涓嬭〃 Using GridData size attributes 涓嶳owData涓嶅悓錛孏ridData榪樻湁寰堝鐨刾ublic灞炴с傚叾涓湁浜涙槸甯冨皵鍊肩被鍨嬬殑錛屼竴鑸細鏍規嵁鎵璁劇疆鐨勪笉鍚宻tyles鑰岃嚜鍔ㄧ鐞嗭紝鎵浠ユ棤闇瀵瑰叾鐩存帴鎿嶄綔銆傝繕鏈変竴浜涙槸integer鍊鹼紝鐢ㄦ潵紜畾鍗曚釜cells鐨勫ぇ灝忋傚叿浣撲歡涓嬭〃錛?br />
]]>5.8 ProgressIndicatorhttp://m.tkk7.com/joeyjong/archive/2006/04/10/40291.htmlJOOJOOMon, 10 Apr 2006 10:07:00 GMThttp://m.tkk7.com/joeyjong/archive/2006/04/10/40291.htmlhttp://m.tkk7.com/joeyjong/comments/40291.htmlhttp://m.tkk7.com/joeyjong/archive/2006/04/10/40291.html#Feedback0http://m.tkk7.com/joeyjong/comments/commentRss/40291.htmlhttp://m.tkk7.com/joeyjong/services/trackbacks/40291.html鍚孭rogressIndicator涓鏍鳳紝瀹冩敮鎸佸伐浣滅殑铏氭嫙鍗曚綅錛寉ou need only initialize the ProgressIndicator with the total amount of work you expect to do and notify it as work is completed:
ProgressIndicator indicator = new ProgressIndicator(parent); ... indicator.beginTask(10); ... Display.getCurrent()display.asyncExec(new Runnable() { public void run() { //Inform the indicator that some amount of work has been done indicator.worked(1); } });
姝e涓婁緥鎵紺猴紝浣跨敤ProgressIndicator闇瑕?姝ワ細 1.璁﹊ndicator鐭ラ亾鎬誨叡鏈夊灝戝伐浣滐紝閫氳繃浣跨敤beginTask().鍙湁榪欎釜鏂規硶琚皟鐢ㄤ簡涔嬪悗錛岃繖涓猚ontrol鎵嶄細鍦ㄥ睆騫曚笂鏄劇ず銆?br />2.姣忓綋鏈変竴閮ㄥ垎宸ヤ綔琚畬鎴愪簡錛屽氨璋冪敤worked()銆備負浜嗛槻姝㈤潪ui鐨勭嚎紼嬫潵update widgets錛屾墍浠ヤ嬌鐢╝syncExec()鏉ヨВ鍐寵繖涓棶棰樸?br /> ProgressIndicator涔熸彁渚沘nimated妯″紡錛屽嵆鎬誨伐浣滈噺涓嶇煡閬撶殑鎯呭喌銆傚湪榪欑妯″紡涓嬶紝the bar continually fills and empties until done() is called. 瑕佷嬌鐢ㄨ繖涓ā寮忥紝灝辮鐢╞eginAnimatedTask()浠f浛beginTask();騫朵笖涓嶉渶瑕亀orked()鏂規硶浜?/font>
]]>5.7 ProgressBarhttp://m.tkk7.com/joeyjong/archive/2006/04/10/40287.htmlJOOJOOMon, 10 Apr 2006 09:56:00 GMThttp://m.tkk7.com/joeyjong/archive/2006/04/10/40287.htmlhttp://m.tkk7.com/joeyjong/comments/40287.htmlhttp://m.tkk7.com/joeyjong/archive/2006/04/10/40287.html#Feedback0http://m.tkk7.com/joeyjong/comments/commentRss/40287.htmlhttp://m.tkk7.com/joeyjong/services/trackbacks/40287.htmlProgressBar錛岃繘搴︽潯錛屾槸ProgressIndicator鐨勭畝鍖栫増鏈傚ぇ澶氭暟鎯呭喌涓嬫帹鑽愪嬌鐢≒rogressIndicator銆傚鏋滀綘鍐沖畾鐩存帴浣跨敤ProgressBar錛岄渶瑕佹墜鍔ㄦ敼鍙樻bar鐨勫瑙傘傚涓?br /> //Style can be SMOOTH, HORIZONTAL, or VERTICAL ProgressBar bar = new ProgressBar(parent, SWT.SMOOTH); bar.setBounds(10, 10, 200, 32); bar.setMaximum(100); ... for(int i = 0; i < 10; i++) { //Take care to only update the display from its //own thread Display.getCurrent().asyncExec(new Runnable() { public void run() { //Update how much of the bar should be filled in bar.setSelection((int)(bar.getMaximum() * (i+1) / 10)); } }); }
setSelection()causes the widget to be updated every time.This behavior is unlike that of ProgressIndicator or ProgressMonitorDialog,which will update the display only if it has changed by an amount that will be visible to the end user.