Topic: 用SWT/JFace如何实现这样的View?

  Print this page

1.用SWT/JFace如何实现这样的View? Copy to clipboard
Posted by: charleszq
Posted on: 2004-03-13 00:38

类似于outlook 2000左面的工具视图,或者象QQ显示头像的视图(同一个category里面的东东可以滚动,不同种类的图标按钮可以分组),用SWT/JFace如何实现?有没有现有的Open Source的代码可以参考?

Thanks.

2.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: Jove
Posted on: 2004-03-13 09:02

可以看一下 VE 的源码
他有类似这样的界面

3.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: charleszq
Posted on: 2004-03-13 10:27

Yes, Jove. Thanks.

VE use GEF to implement this and GEF can really meet my requirement. I've already implemented my own GEF editor just like the picture you showed above. But the problems is maybe I can not use GEF for certain reasons. So I want know if there are some simple ways to do this, use just SWT/JFace, GEF palette might be too heavy weight for me.

Smile

4.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: Jove
Posted on: 2004-03-13 16:28

或许你可以去看看GEF的源码, 不过他的实现或许比较MVC

一个Quick And Ditry的实现应该不太麻烦

5.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: charleszq
Posted on: 2004-03-13 22:29

Thanks again, Jove.

If I'm right, you did the code for the above screenshot, right? You're so fast!

Trying to do some test on this. Smile

6.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: Jove
Posted on: 2004-03-14 14:12

你看下面的效果如何? Big Smile

源代码
我是在Eclipse 3.0 M7中编的,使用了SWT-Designer
非这个版本的eclipse,打开此项目可能会报swt.jar没找到,请自行指定eclipse/plugin目录对应版本的swt

7.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: charleszq
Posted on: 2004-03-15 12:12

:-o 太牛了!就是,能不能把代码给咱们参考一下?charleszq@163.com

Thanks.

8.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: Jove
Posted on: 2004-03-15 12:27

谬赞谬赞, 没什么技巧在里面
//而且面板的滚动条也没搞定

源码等我晚上回去后贴上来, 现在不在手头.

9.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: 忧郁海风
Posted on: 2004-03-15 13:20

真的很帅啊!

10.Re:用SWT/JFace如何实现这样的View? [Re: Jove] Copy to clipboard
Posted by: Jove
Posted on: 2004-03-15 23:33

源代码:

FakeQQ.zip (98.24k)

11.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: charleszq
Posted on: 2004-03-16 12:15

Thanks. Studying...

12.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: floater
Posted on: 2004-03-17 01:06

Here is a simple swing version, really just one class. I just use simple JLabels for testing. You may put pictures into JLabels and shift the text to the bottom.

There are two counts of [i] in the code when I used colorj to convert, so I include the java file as well.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class AddComponentButton extends JButton
{
AddComponentButton(String name)
{
super(name);
addListener();
}

private void addListener()
{
addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent actionEvent)
{
JComponent aa = (JComponent)actionEvent.getSource();
JComponent panel = (JComponent)aa.getParent();
int pos = find(panel, aa);

if (pos != -1)
{
panel.add(new JLabel("This is a test"), pos + 1);
panel.add(new JLabel("This is a test"), pos + 2);
panel.add(new JLabel("This is a test"), pos + 3);
}
panel.validate();
}

private int find(JComponent jc, JComponent ijc)
{
Component[] comp = jc.getComponents();

// remove old JLabels if any
for (int i=0, j=comp.length; i<j; i++)
{
// here, we have to know what kind of components we want to remove.
if (comp instanceof JLabel) jc.remove(comp[i]);
}

[i]// now find the position for the component ijc

comp = jc.getComponents(); // it's been changed, so get it again.
for (int i=0, j=comp.length; i<j; i++)
{
if (comp == ijc) return i;
}
return -1;
}
}
);
}

public static void main(String[] args)
{
JFrame frame = new JFrame("Add/remove components");
frame.setSize(100 , 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(new AddComponentButton("Button 1"));
panel.add(new AddComponentButton("Button 2"));
panel.add(new AddComponentButton("Button 3"));
panel.add(new AddComponentButton("Button 4"));
panel.add(new AddComponentButton("Button 5"));

frame.getContentPane().add(panel);

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
if (frameSize.height > screenSize.height) frameSize.height = screenSize.height;
if (frameSize.width > screenSize.width) frameSize.width = screenSize.width;
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);

[i]// don't do this, because it will shrink the frame size to the compact level

// and thus we won't have the space to expand. Hopefully, this won't cause
// and any issue since we use a single frame anyway.
//frame.pack();
frame.setVisible(true);
}
}



AddComponentButton.java (3.05k)

13.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: charleszq
Posted on: 2004-03-17 20:48

Thanks, floater. So many warm-hearted people here.

14.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: Dracula
Posted on: 2004-03-17 23:12

哇塞,真的是一群牛人啊,我什么时候才能练到这种程度啊,一定继续想大家学习!~ 真羡慕你们!~

15.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: glistar
Posted on: 2004-03-18 09:56

Jove 兄,您的 M7 的界面这么酷,怎么搞出来的?分享一下?
3x

16.Re:用SWT/JFace如何实现这样的View? [Re: glistar] Copy to clipboard
Posted by: Jove
Posted on: 2004-03-18 10:02

http://www.cjsdn.com/post/view?bid=7&id=80744&sty=2&keywords=M7+ui

17.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: charleszq
Posted on: 2004-03-23 20:27

Jove, How about the scroll bar of the ScrolledComposite? I found that ScrolledComposite can not set the Layout (In setLayout() of it, there is a comment), but you do set the Layout to it. Do you figure out the problem?

18.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: charleszq
Posted on: 2004-03-23 20:30

另外,我看了GEF中的PaletteView,如果它的COLUMNS的那种layout可以设置column = 1的话,上面的这个问题就比较圆满了。但现在不知道如何设置。:S

19.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: Jove
Posted on: 2004-03-23 21:16

ScrolledComposite确实不需要setLayout的
那个是SWT-Designer自动填的 (有个选项,子容器自动使用父容器的layout)

不过滚动那个确实没有搞定 Embaressed
要比较全面的实现这样的控件,确实还要花很多功夫,我这个只是一个Quick and Dirty的实现

SWT我只用过一两个月,现在被老板逼着用Delphi Cry
大侠你好好努力,做完别忘了share一个 Kiss

20.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: lxh_ming
Posted on: 2004-03-24 10:03

不错,就是不喜欢eclipse的动不动就自动编译,我的系统太差了,承受不起

21.Re:用SWT/JFace如何实现这样的View? [Re: lxh_ming] Copy to clipboard
Posted by: Jove
Posted on: 2004-03-24 10:17



22.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: charleszq
Posted on: 2004-03-24 12:03

问了GEF News Group中的专家,PaletteViewer的COLUMNS layout如果想让用户设置其column number,要等到3.0release了。Cry

23.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: kite
Posted on: 2004-03-24 16:56

这个如何?

(缩略图,点击图片链接看原图)

24.Re:用SWT/JFace如何实现这样的View? [Re: kite] Copy to clipboard
Posted by: Jove
Posted on: 2004-03-24 17:08

kite wrote:
这个如何?


Oh My God Linux上的SWT?

25.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: kite
Posted on: 2004-03-24 17:14

不是,完全是基于SWT的,可以运行在所有支持SWT的平台上

26.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: charleszq
Posted on: 2004-03-24 19:14

Can you share the source code?

27.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: kite
Posted on: 2004-03-24 19:20

目前的代码比较初级,等我整理一下,就贴上来

28.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: kite
Posted on: 2004-03-27 17:00

由于附近大小的限制,只上载了源码,不包含测试用的image文件。

outlookbar.zip (21.16k)

29.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: zzy2004
Posted on: 2004-04-20 14:58

那我怎么才能运行它刚刚学习,下载了你得东东,就是运行不起来,我用得是3。0

30.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: kite
Posted on: 2004-04-21 10:48

修改Main.java,使所用的image文件指向你自己的文件。重新编译。

31.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: zzy2004
Posted on: 2004-04-22 15:12

编译报错如下:
java.lang.UnsatisfiedLinkError: no swt-win32-3038 in java.library.path
  at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1403)
  at java.lang.Runtime.loadLibrary0(Runtime.java:788)
  at java.lang.System.loadLibrary(System.java:832)
  at org.eclipse.swt.internal.Library.loadLibrary(Library.java:100)
  at org.eclipse.swt.internal.win32.OS.<clinit>(OS.java:46)
  at org.eclipse.swt.widgets.Display.internal_new_GC(Display.java:1548)
  at org.eclipse.swt.graphics.Device.init(Device.java:541)
  at org.eclipse.swt.widgets.Display.init(Display.java:1573)
  at org.eclipse.swt.graphics.Device.<init>(Device.java:96)
  at org.eclipse.swt.widgets.Display.<init>(Display.java:331)
  at org.eclipse.swt.widgets.Display.<init>(Display.java:327)
  at org.eclipse.swt.custom.outlookbar.Main.main(Main.java:11)
Exception in thread "main"
//对了,老大,我已经做好了一个java版的qq,可是,现在的问题是,我想做出一个不规则界面来,像qq一样,java li lzen怎么实现呢,我都郁闷很久了,还有,你那个工程,我怎么编译不了呢,能把整个工程极设置发给我吗?我不胜感激,谢谢,谢谢。zhyzhao@thunis.com

32.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: kite
Posted on: 2004-04-24 22:25

你这是运行错误,不是编译错误,要把你所用的swt.jar所需要的dll放到能找到的地方,如:放到system32目录下,或放到当前目录下,或用-Djava.library.path=[driver]:\xx\xx\来指定。

33.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: kite
Posted on: 2004-04-25 22:46

如果你用的是SWT的话,你可以看一下这里:http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/platform-swt-home/snippits/snippet134.html

34.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: yanwj
Posted on: 2004-05-07 23:30

我觉得参考CTabFolder和CTabItem这两个类会有所启发.这两我模仿这个结构,写了个程序,实现了这样的界面,还是比较轻松的

35.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: chenyajun5
Posted on: 2004-05-08 12:12

在Swing中如何实现这种效果?

36.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: freecode
Posted on: 2004-05-10 13:56

要抓紧时间学习了。

37.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: frozen
Posted on: 2004-05-22 14:07

我看到过的lumaQQ带的Shutter控件就是你所说的那种

38.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: xidianliuy
Posted on: 2004-06-16 19:23

强人

39.Re:用SWT/JFace如何实现这样的View? [Re: kite] Copy to clipboard
Posted by: cyclamen
Posted on: 2004-07-07 14:56

强啊,这些类是你自己些的么,还是用工具产生的
我想用啊

kite wrote:
由于附近大小的限制,只上载了源码,不包含测试用的image文件。

40.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: kite
Posted on: 2004-07-09 14:20

自己写的,用吧。

41.Re:用SWT/JFace如何实现这样的View? [Re: kite] Copy to clipboard
Posted by: redlly
Posted on: 2004-07-16 19:14

你的源代码我看了一下,在eclipse3.0中可以运行,但我只是在调试环境下运行成功,打包成jar文件就不行了。提示如下:
E:\eclipse-SDK-3.0-win32\eclipse\workspace\FakeQQ>java -jar FakeQQ.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/swt/widgets/Layout

我如果想把一个SWT应用程序打包成jar文件,swt.jar所需要的dll文件应该怎么放?是放在jar文件里面还是外面?具体该怎么配置?

kite wrote:
你这是运行错误,不是编译错误,要把你所用的swt.jar所需要的dll放到能找到的地方,如:放到system32目录下,或放到当前目录下,或用-Djava.library.path=[driver]:\xx\xx\来指定。


java.library.path是什么?你这里所指的“-Djava.library.path=[driver]:\xx\xx\” 是什么意思?

42.Re:用SWT/JFace如何实现这样的View? [Re: charleszq] Copy to clipboard
Posted by: DengHT
Posted on: 2004-09-01 22:54

你只需将*.dll文件拷贝到System32目录下就可以了。

43.Re:用SWT/JFace如何实现这样的View? [Re: Dracula] Copy to clipboard
Posted by: littledeer1974
Posted on: 2004-09-13 17:06

好东西


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923