クールバーはマウスでドラッグすることで配置を変更することのできるツールバーです。見た目はツールバーに似ていますが、操作はかなり複雑になっています。基本的にはCoolBarの子としてCoolItemを作成し、CoolItem#setControlでCoolItemに任意のコントロールを貼り付けるという感じになります。この際、CoolItemがCoolBar上でドラッグ可能な区画となります。また、きちんと表示するにはCoolItemに対するサイズの指定も必要です。
import org.eclipse.swt.*; import org.eclipse.swt.layout.*; import org.eclipse.swt.widgets.*; import org.eclipse.swt.graphics.*; public class CoolBarSample1 { public static void main (String [] args) { Display display = new Display (); Shell shell =new Shell(display); shell.setText("CoolBar Sample1"); shell.setLayout(new FillLayout()); CoolBar coolbar = new CoolBar(shell,SWT.NULL); ToolBar toolbar1 = new ToolBar(coolbar,SWT.FLAT); ToolItem tItem1_1 = new ToolItem(toolbar1,SWT.PUSH); tItem1_1.setText("Item1"); ToolItem tItem1_2 = new ToolItem(toolbar1,SWT.PUSH); tItem1_2.setText("Item2"); CoolItem item1 = new CoolItem(coolbar,SWT.PUSH); item1.setControl(toolbar1); Point pt1 = toolbar1.computeSize(SWT.DEFAULT,SWT.DEFAULT); pt1 = item1.computeSize(pt1.x,pt1.y); item1.setSize(pt1); ToolBar toolbar2 = new ToolBar(coolbar,SWT.FLAT); ToolItem tItem2_1 = new ToolItem(toolbar2,SWT.PUSH); tItem2_1.setText("Item3"); CoolItem item2 = new CoolItem(coolbar,SWT.PUSH); item2.setControl(toolbar2); Point pt2 = toolbar2.computeSize(SWT.DEFAULT,SWT.DEFAULT); pt2 = item2.computeSize(pt2.x,pt2.y); item2.setSize(pt2); shell.setSize(200,80); shell.open(); while (!shell.isDisposed ()){ if (!display.readAndDispatch ()){ display.sleep (); } } display.dispose (); } }
最終更新時間:2004年03月09日 03時47分34秒