在ToolBar左右加上两个箭头按钮,点击箭头按钮,可以使ToolBar左右移动 , 希望有源代码. (高分求!!!) 在ToolBar左右加上两个箭头按钮,点击箭头按钮,可以使ToolBar左右移动, 希望能有源代码. 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我在JToolBar上面加了几个JButton。发现我要加的东西太多了,需要左右滚动一下。不知道如何实现这个功能。就是中间是一排button图标,然后点左边箭头,这些button就向左移动,至少看上去是,点右面箭头同理。当点右到头的时候,箭头变不可用。 可拖动的应该是CoolBarimport org.eclipse.swt.SWT;import org.eclipse.swt.graphics.Point;import org.eclipse.swt.layout.*;import org.eclipse.swt.widgets.*;public class CoolBarSample { public static void main(String[] args) { Display display = new Display (); Shell shell = new Shell (display); shell.setText("CoolBar"); shell.setLayout( new GridLayout()); Composite tool = new Composite( shell ,SWT.NONE); tool.setLayoutData(new GridData(SWT.LEFT,SWT.TOP,true ,false)); //定义可拖动的工具栏对象 CoolBar coolBar = new CoolBar (tool, SWT.FLAT); //创建两个工具栏项 createItem(display ,coolBar); createItem(display,coolBar); coolBar.pack (); Text content = new Text (shell,SWT.MULTI); content.setLayoutData( new GridData(SWT.FILL,SWT.FILL,true,true)); shell.setSize( new Point ( 200,150 )); shell.open (); while (!shell.isDisposed()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); } public static CoolItem createItem(Display display ,CoolBar coolBar) { //创建一个工具栏 ToolBar toolBar = createToolBar(display, coolBar); //获得工具栏的大小 Point size = toolBar.getSize(); //定义一个CoolItem对象 CoolItem item = new CoolItem(coolBar, SWT.NONE); //将工具栏绑定到这个工具栏项上 item.setControl(toolBar); //计算工具栏项合适的大小 Point preferred = item.computeSize(size.x, size.y); //设置大小 item.setPreferredSize(preferred); return item; } public static ToolBar createToolBar(Display display, CoolBar coolBar) { ToolBar toolBar = new ToolBar(coolBar, SWT.FLAT); //创建保存工具按钮 ToolItem saveItem = new ToolItem ( toolBar , SWT.PUSH); //设置工具按钮上的文字 saveItem.setText("保存"); //设置工具按钮上的提示信息 saveItem.setToolTipText("保存"); //创建打印工具按钮 ToolItem printItem = new ToolItem ( toolBar , SWT.PUSH); printItem.setText("打印"); printItem.setToolTipText("打印"); //创建帮助工具按钮 ToolItem helpItem = new ToolItem ( toolBar , SWT.PUSH); helpItem.setText("帮助"); helpItem.setToolTipText("帮助"); toolBar.pack(); return toolBar; }}希望对你有帮助~~~ import org.eclipse.swt.SWT;import org.eclipse.swt.graphics.Point;import org.eclipse.swt.layout.*;import org.eclipse.swt.widgets.*;public class CoolBarSample {public static void main(String[] args) {Display display = new Display ();Shell shell = new Shell (display);shell.setText("CoolBar");shell.setLayout( new GridLayout());Composite tool = new Composite( shell ,SWT.NONE);tool.setLayoutData(new GridData(SWT.LEFT,SWT.TOP,true ,false));//定义可拖动的工具栏对象CoolBar coolBar = new CoolBar (tool, SWT.FLAT);//创建两个工具栏项 createItem(display ,coolBar); createItem(display,coolBar);coolBar.pack ();Text content = new Text (shell,SWT.MULTI);content.setLayoutData( new GridData(SWT.FILL,SWT.FILL,true,true));shell.setSize( new Point ( 200,150 ));shell.open ();while (!shell.isDisposed()) {if (!display.readAndDispatch ()) display.sleep ();}display.dispose ();}public static CoolItem createItem(Display display ,CoolBar coolBar) {//创建一个工具栏 ToolBar toolBar = createToolBar(display, coolBar); //获得工具栏的大小 Point size = toolBar.getSize(); //定义一个CoolItem对象 CoolItem item = new CoolItem(coolBar, SWT.NONE); //将工具栏绑定到这个工具栏项上 item.setControl(toolBar); //计算工具栏项合适的大小 Point preferred = item.computeSize(size.x, size.y); //设置大小 item.setPreferredSize(preferred); return item;}public static ToolBar createToolBar(Display display, CoolBar coolBar) {ToolBar toolBar = new ToolBar(coolBar, SWT.FLAT);//创建保存工具按钮ToolItem saveItem = new ToolItem ( toolBar , SWT.PUSH);//设置工具按钮上的文字saveItem.setText("保存");//设置工具按钮上的提示信息saveItem.setToolTipText("保存");//创建打印工具按钮ToolItem printItem = new ToolItem ( toolBar , SWT.PUSH);printItem.setText("打印");printItem.setToolTipText("打印");//创建帮助工具按钮ToolItem helpItem = new ToolItem ( toolBar , SWT.PUSH);helpItem.setText("帮助");helpItem.setToolTipText("帮助"); toolBar.pack();return toolBar;}} 重发下,刚才没注意加亮 呵呵,多谢楼上的,不过好像楼上的只能是在Eclipse上运行吧?有没有通用的用纯Java实现的,因为我们开发的不是用的Eclipse 直接把SWT/JFace的包加进去不就行了 关于JTable的一个问题 谁知道这是java的哪本教程 根据方法名利用反射机制调用该方法 String类型的对象是不可改变的.这句话怎么理解? 如何更换JAVA应用程序的窗体图标? 在oracle9i里存韩文,有的字正常,有的字是乱码,谁见过? 为什么不能删除.txt临时文件 再问关于同一个FRAME里面,ItemListener互相干扰的问题 method vs class 小问题,过来看,可以的话把20拿走:) java中正則表達式的寫法 org.eclipse.swt包的问题
就是中间是一排button图标,然后点左边箭头,这些button就向左移动,至少看上去是,点右面箭头同理。
当点右到头的时候,箭头变不可用。
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;public class CoolBarSample { public static void main(String[] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setText("CoolBar");
shell.setLayout( new GridLayout());
Composite tool = new Composite( shell ,SWT.NONE);
tool.setLayoutData(new GridData(SWT.LEFT,SWT.TOP,true ,false));
//定义可拖动的工具栏对象
CoolBar coolBar = new CoolBar (tool, SWT.FLAT);
//创建两个工具栏项
createItem(display ,coolBar);
createItem(display,coolBar);
coolBar.pack ();
Text content = new Text (shell,SWT.MULTI);
content.setLayoutData( new GridData(SWT.FILL,SWT.FILL,true,true));
shell.setSize( new Point ( 200,150 ));
shell.open ();
while (!shell.isDisposed()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose (); }
public static CoolItem createItem(Display display ,CoolBar coolBar) {
//创建一个工具栏
ToolBar toolBar = createToolBar(display, coolBar);
//获得工具栏的大小
Point size = toolBar.getSize();
//定义一个CoolItem对象
CoolItem item = new CoolItem(coolBar, SWT.NONE);
//将工具栏绑定到这个工具栏项上
item.setControl(toolBar);
//计算工具栏项合适的大小
Point preferred = item.computeSize(size.x, size.y);
//设置大小
item.setPreferredSize(preferred);
return item;
}
public static ToolBar createToolBar(Display display, CoolBar coolBar) {
ToolBar toolBar = new ToolBar(coolBar, SWT.FLAT);
//创建保存工具按钮
ToolItem saveItem = new ToolItem ( toolBar , SWT.PUSH);
//设置工具按钮上的文字
saveItem.setText("保存");
//设置工具按钮上的提示信息
saveItem.setToolTipText("保存");
//创建打印工具按钮
ToolItem printItem = new ToolItem ( toolBar , SWT.PUSH);
printItem.setText("打印");
printItem.setToolTipText("打印");
//创建帮助工具按钮
ToolItem helpItem = new ToolItem ( toolBar , SWT.PUSH);
helpItem.setText("帮助");
helpItem.setToolTipText("帮助");
toolBar.pack();
return toolBar;
}
}
希望对你有帮助~~~
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;public class CoolBarSample {public static void main(String[] args) {
Display display = new Display ();
Shell shell = new Shell (display);
shell.setText("CoolBar");
shell.setLayout( new GridLayout());
Composite tool = new Composite( shell ,SWT.NONE);
tool.setLayoutData(new GridData(SWT.LEFT,SWT.TOP,true ,false));
//定义可拖动的工具栏对象
CoolBar coolBar = new CoolBar (tool, SWT.FLAT);
//创建两个工具栏项
createItem(display ,coolBar);
createItem(display,coolBar);
coolBar.pack ();
Text content = new Text (shell,SWT.MULTI);
content.setLayoutData( new GridData(SWT.FILL,SWT.FILL,true,true));
shell.setSize( new Point ( 200,150 ));
shell.open ();
while (!shell.isDisposed()) {
if (!display.readAndDispatch ()) display.sleep ();
}
display.dispose ();}
public static CoolItem createItem(Display display ,CoolBar coolBar) {
//创建一个工具栏
ToolBar toolBar = createToolBar(display, coolBar);
//获得工具栏的大小
Point size = toolBar.getSize();
//定义一个CoolItem对象
CoolItem item = new CoolItem(coolBar, SWT.NONE);
//将工具栏绑定到这个工具栏项上
item.setControl(toolBar);
//计算工具栏项合适的大小
Point preferred = item.computeSize(size.x, size.y);
//设置大小
item.setPreferredSize(preferred);
return item;
}
public static ToolBar createToolBar(Display display, CoolBar coolBar) {
ToolBar toolBar = new ToolBar(coolBar, SWT.FLAT);
//创建保存工具按钮
ToolItem saveItem = new ToolItem ( toolBar , SWT.PUSH);
//设置工具按钮上的文字
saveItem.setText("保存");
//设置工具按钮上的提示信息
saveItem.setToolTipText("保存");
//创建打印工具按钮
ToolItem printItem = new ToolItem ( toolBar , SWT.PUSH);
printItem.setText("打印");
printItem.setToolTipText("打印");
//创建帮助工具按钮
ToolItem helpItem = new ToolItem ( toolBar , SWT.PUSH);
helpItem.setText("帮助");
helpItem.setToolTipText("帮助");
toolBar.pack();
return toolBar;
}
} 重发下,刚才没注意加亮