我发现ScrolledComposite监听鼠标滚轮时,如果其parent是如tabFolder这样的组件时,就不响应滚轮事件了,请问谁能解决?
另问事件监听器里怎么响应鼠标滚轮?我查了MouseEvent里是没有的,MouseWheelListener用的也是MouseEvent.//这些是在createComponet里
shell = new Shell();
shell.setSize(500, 375);
shell.setText("SWT Application");
shell.setLayout(new FormLayout());//这里是创建TabFolder
TabFolder t = new TabFolder(shell, SWT.NONE);
t.setBounds(0,0,500,375);
TabItem ti = new TabItem(t, SWT.NONE);
ti.setText("abc");
//这些是生成内容
a = new Composite(t, SWT.NONE);
FormData af = new FormData();
af.top = new FormAttachment(0,100,0);
af.bottom = new FormAttachment(100,100,0);
af.left = new FormAttachment(0,100,0);
af.right = new FormAttachment(100,100,0);
a.setLayoutData(af);
a.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
ScrolledComposite aa = new ScrolledComposite(a, SWT.H_SCROLL);
aa.setBounds(0,0,475,320);
ScrolledComposite b = new ScrolledComposite(aa, SWT.V_SCROLL);
b.setBounds(0,0,475,320);
b.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
Composite c = new Composite(b, SWT.NONE);
c.setBounds(0,0,1000, 100);
c.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
Composite cc = new Composite(b, SWT.NONE);
cc.setBounds(0,100,1000,1000);
for(int i = 0; i < 1000/20; i++){
Label l = new Label(cc, SWT.NONE);
l.setBounds(0,20*i,20,20);
l.setText(""+i);
}
aa.setContent(c);
b.setContent(cc);ti.setControl(test.a);
另问事件监听器里怎么响应鼠标滚轮?我查了MouseEvent里是没有的,MouseWheelListener用的也是MouseEvent.//这些是在createComponet里
shell = new Shell();
shell.setSize(500, 375);
shell.setText("SWT Application");
shell.setLayout(new FormLayout());//这里是创建TabFolder
TabFolder t = new TabFolder(shell, SWT.NONE);
t.setBounds(0,0,500,375);
TabItem ti = new TabItem(t, SWT.NONE);
ti.setText("abc");
//这些是生成内容
a = new Composite(t, SWT.NONE);
FormData af = new FormData();
af.top = new FormAttachment(0,100,0);
af.bottom = new FormAttachment(100,100,0);
af.left = new FormAttachment(0,100,0);
af.right = new FormAttachment(100,100,0);
a.setLayoutData(af);
a.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK));
ScrolledComposite aa = new ScrolledComposite(a, SWT.H_SCROLL);
aa.setBounds(0,0,475,320);
ScrolledComposite b = new ScrolledComposite(aa, SWT.V_SCROLL);
b.setBounds(0,0,475,320);
b.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_RED));
Composite c = new Composite(b, SWT.NONE);
c.setBounds(0,0,1000, 100);
c.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
Composite cc = new Composite(b, SWT.NONE);
cc.setBounds(0,100,1000,1000);
for(int i = 0; i < 1000/20; i++){
Label l = new Label(cc, SWT.NONE);
l.setBounds(0,20*i,20,20);
l.setText(""+i);
}
aa.setContent(c);
b.setContent(cc);ti.setControl(test.a);
* Created on 2008/04/29
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package swt;import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.graphics.Point;/**
* @author qingkangxu
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class TabFolderTest { public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display, SWT.SHELL_TRIM);
shell.setText("TabFolder");
shell.setLayout(new FillLayout()); TabFolder folder = new TabFolder(shell, SWT.NONE);
TabItem item1 = new TabItem(folder, SWT.NONE);
item1.setText("label");
// create the sc
final ScrolledComposite sc = new ScrolledComposite(folder, SWT.V_SCROLL);
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.getVerticalBar().setIncrement(5); // create the composite on the sc
final Composite endpointComp = new Composite(sc, SWT.NONE);
GridData suGridData = new GridData(GridData.FILL_BOTH);
endpointComp.setLayoutData(suGridData);
endpointComp.setLayout(new GridLayout(1, true));
//add button to the endpointComp
addCompToEndpointComp(endpointComp); sc.addControlListener(new ControlAdapter() {
public void controlResized(ControlEvent e) { Point p = endpointComp.computeSize(SWT.DEFAULT, SWT.DEFAULT);
sc.setMinSize(p.x, p.y + 10);
endpointComp.layout();
}
});
sc.setContent(endpointComp);
item1.setControl(sc); TabItem item2 = new TabItem(folder, SWT.NONE);
item2.setText("radio");
Group group2 = new Group(folder, SWT.NONE);
group2.setText("Radio Group");
group2.setLayout(new GridLayout());
Button radio1 = new Button(group2, SWT.RADIO);
radio1.setText("radio1");
Button radio2 = new Button(group2, SWT.RADIO);
radio2.setText("radio2");
item2.setControl(group2); shell.setVisible(true);
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
} private static void addCompToEndpointComp(Composite endpointComp) {
for (int i = 0; i < 20; i++) {
Button button = new Button(endpointComp, SWT.PUSH);
button.setText("ForTestBtn"+i);
button.setLayoutData(new GridData());
} }
}