在ToolBar左右加上两个箭头按钮,点击箭头按钮,可以使ToolBar左右移动 , 希望有源代码. (高分求!!!)

OPENDREAM 2008-06-08 06:58:52
在ToolBar左右加上两个箭头按钮,点击箭头按钮,可以使ToolBar左右移动, 希望能有源代码.
...全文
367 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
spiderman23 2010-09-16
  • 打赏
  • 举报
回复
我iekj 书法家说了看见
icyice1989 2008-06-11
  • 打赏
  • 举报
回复
直接把SWT/JFace的包加进去不就行了
OPENDREAM 2008-06-10
  • 打赏
  • 举报
回复
呵呵,多谢楼上的,不过好像楼上的只能是在Eclipse上运行吧?有没有通用的用纯Java实现的,因为我们开发的不是用的Eclipse
icyice1989 2008-06-09
  • 打赏
  • 举报
回复
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;
}
}


重发下,刚才没注意加亮
icyice1989 2008-06-09
  • 打赏
  • 举报
回复
可拖动的应该是CoolBar

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;
}
}
希望对你有帮助~~~
OPENDREAM 2008-06-08
  • 打赏
  • 举报
回复
呵呵,由于我是新手,还劳烦楼上的能详细说明下,最好能有代码表示下,不胜感谢!
KKK2007 2008-06-08
  • 打赏
  • 举报
回复
swt轻松搞顶
OPENDREAM 2008-06-08
  • 打赏
  • 举报
回复
我在JToolBar上面加了几个JButton。发现我要加的东西太多了,需要左右滚动一下。不知道如何实现这个功能。
就是中间是一排button图标,然后点左边箭头,这些button就向左移动,至少看上去是,点右面箭头同理。
当点右到头的时候,箭头变不可用。

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧