Topic: 请教一个关于SashFORM的问题!请各位帮忙!

  Print this page

1.请教一个关于SashFORM的问题!请各位帮忙! Copy to clipboard
Posted by: liankun
Posted on: 2004-10-28 14:00

开发中遇到如下问题,我在SASHFORM中添加的控件如果嵌套的层次比较多,则会出现刷新的问题。
如下的代码,我加了一个表格到SASHFORM中去,该表格在双击SHELL最大化的时候,刷新异常。表格添加是在方法PPP中!

请高手指点:


/*
* Created on 2004-10-25
*/
package org.jeff.swt;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.SashForm;
import org.eclipse.swt.custom.StackLayout;
import org.eclipse.swt.events.*;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

/**
* @author JeffLian.
*/
public class T08 {

public static void main(String[] args) {

final Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());

JComposite parent1 = new JComposite(shell, SWT.NONE);
parent1.setLayout(new FillLayout());

JComposite parent = new JComposite(parent1, SWT.BORDER);

GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.verticalSpacing = 0;
parent.setLayout(layout);

JComposite pane = new JComposite(parent, SWT.BORDER);
pane.setLayoutData(new GridData(GridData.FILL_BOTH));
pane.setLayout(new FillLayout());

JComposite aa = new JComposite(pane, SWT.NONE);
createPartControl(aa);

shell.setBounds(20, 30, 500, 500);
shell.open();
while (!shell.isDisposed()){
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();

}

public static void createPartControl(JComposite parent) {
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.verticalSpacing = 0;
parent.setLayout(layout);

JComposite control = new JComposite(parent, SWT.BORDER);
control.setLayoutData(new GridData(GridData.FILL_BOTH));

GridLayout controlLayout = new GridLayout();
controlLayout.horizontalSpacing = 0;
controlLayout.verticalSpacing = 0;
controlLayout.marginHeight = 0;
controlLayout.marginWidth = 0;

control.setLayout(controlLayout);

JComposite contentArea = new JComposite(control, SWT.NONE);
GridData clientData = new GridData(GridData.FILL_BOTH);
contentArea.setLayoutData(clientData);

//StackLayout contentLayout = new StackLayout();
//contentArea.setLayout(contentLayout);
contentArea.setLayout(new FillLayout());

JComposite ppp = new JComposite(contentArea, SWT.NONE);
PPP(ppp);

//contentLayout.topControl = ppp;
if (parent != null) return;
}

public static void PPP(JComposite parent) {
GridLayout layout = new GridLayout();
layout.marginHeight = 0;
layout.marginWidth = 0;
layout.verticalSpacing = 0;
parent.setLayout(layout);

JComposite pane1 = new JComposite(parent, SWT.BORDER);
pane1.setLayoutData(new GridData(GridData.FILL_BOTH));

pane1.setLayout(new GridLayout());

Label label = new Label(pane1, SWT.PUSH);
label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
label.setText("sdfsdf");

//SashForm form = new SashForm(pane1, SWT.VERTICAL);

//sashform在此处添加。

final SashForm form = new SashForm(pane1, SWT.VERTICAL);
form.setLayoutData(new GridData(GridData.FILL_BOTH));
form.setLayout(new GridLayout());

JComposite child1 = new JComposite(form, SWT.NONE);
child1.setLayoutData(new GridData(GridData.FILL_BOTH));
child1.setLayout(new FillLayout());
//table = new CTable(child1, new CellDisplay(), new Renderer());
new Label(child1, SWT.NONE).setText("Label in pane 1");

JComposite child2 = new JComposite(form, SWT.NONE);
child2.setLayoutData(new GridData(GridData.FILL_BOTH));
child2.setLayout(new FillLayout());
new Button(child2, SWT.PUSH).setText("Button in pane2");

final JComposite child3 = new JComposite(form, SWT.NONE);
child3.setLayoutData(new GridData(GridData.FILL_BOTH));
child3.setLayout(new GridLayout());

final JComposite ccc = new JComposite(child3, SWT.BORDER);
ccc.setLayoutData(new GridData(GridData.FILL_BOTH));
ccc.setLayout(new GridLayout());

final JComposite ddd = new JComposite(ccc, SWT.BORDER);
ddd.setLayoutData(new GridData(GridData.FILL_BOTH));
ddd.setLayout(new GridLayout());

//此处的表格多嵌套了几个COMPOSITE,

final Table table = new Table(ddd, SWT.FULL_SELECTION);
table.setLayoutData(new GridData(GridData.FILL_BOTH));

table.setItemCount(10);
table.setHeaderVisible(true);
table.setLinesVisible(true);

TableColumn col1 = new TableColumn(table, SWT.CENTER);
col1.setText(" col1");
col1.setWidth(90);
TableColumn col2 = new TableColumn(table, SWT.CENTER);
col2.setText(" col2");
col2.setWidth(90);

for (int i = 0; i < 10; i++){
TableItem item = new TableItem(table, SWT.NONE);
item.setText(new String[] { "row", "row" + i });
item.setImage(0, null);
}

table.addControlListener(new ControlAdapter(){
/* (non-Javadoc)
* @see org.eclipse.swt.events.ControlAdapter#controlMoved(org.eclipse.swt.events.ControlEvent)
*/
public void controlMoved(ControlEvent e) {
System.out.println("table moved: "+ table.getBounds() );
}

/* (non-Javadoc)
* @see org.eclipse.swt.events.ControlAdapter#controlResized(org.eclipse.swt.events.ControlEvent)
*/
public void controlResized(ControlEvent e) {
System.out.println("table resized: "+ table.getBounds() );
}
});

table.getShell().addControlListener(new ControlListener() {
public void controlMoved(ControlEvent e) {
System.out.println("shell moved, ");
form.layout(true);

}

public void controlResized(ControlEvent e) {
System.out.println("shell resized, table bound: " + table.getBounds());
form.layout(true);
table.redraw();
}
});

child3.addControlListener(new ControlListener() {
public void controlMoved(ControlEvent e) {
System.out.println("child3 moved, ");
}

public void controlResized(ControlEvent e) {
System.out.println("child3 resized, " + child3.getBounds());
}
});

ccc.addControlListener(new ControlListener() {
public void controlMoved(ControlEvent e) {
System.out.println("ccc moved, ");
}

public void controlResized(ControlEvent e) {
System.out.println("ccc resized, " + ccc.getBounds());
}
});

ddd.addControlListener(new ControlListener() {
public void controlMoved(ControlEvent e) {
System.out.println("ddd moved, ");
}

public void controlResized(ControlEvent e) {
System.out.println("ddd resized, " + ddd.getBounds());
table.setBounds(ddd.getBounds());
table.redraw();
}
});


form.setWeights(new int[] { 30, 40, 30 });

if (form != null) return;

}


public static class JComposite extends Composite{

/**
*
*/
JComposite(Composite parent, int style) {
super(parent, style);
}


/* (non-Javadoc)
* @see org.eclipse.swt.widgets.JComposite#layout()
*/
public void layout() {
System.out.println("layout");
super.layout();
}


/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Composite#layout(boolean)
*/
public void layout(boolean changed) {
System.out.println("layout");
super.layout(changed);
}
}
}

2.Re:请教一个关于SashFORM的问题!请各位帮忙! [Re: liankun] Copy to clipboard
Posted by: liankun
Posted on: 2004-10-28 19:31

SuN034

PLS HELP ME !

3.Re:请教一个关于SashFORM的问题!请各位帮忙! [Re: liankun] Copy to clipboard
Posted by: kavinwang
Posted on: 2004-10-29 09:04

我倒是想帮你,可是我对swt不熟悉,唉!

4.Re:请教一个关于SashFORM的问题!请各位帮忙! [Re: liankun] Copy to clipboard
Posted by: liankun
Posted on: 2004-10-29 16:43

难道此处没有高人!!

5.Re:请教一个关于SashFORM的问题!请各位帮忙! [Re: liankun] Copy to clipboard
Posted by: kavinwang
Posted on: 2004-10-29 16:50

liankun wrote:
难道此处没有高人!!

看起来没有!

6.Re:请教一个关于SashFORM的问题!请各位帮忙! [Re: liankun] Copy to clipboard
Posted by: xiaomage234
Posted on: 2004-10-30 15:03

liankun:

我试了一下,没有异常啊

这是打出来的信息:

shell moved,
shell resized, table bound: Rectangle {0, 0, 0, 0}
child3 moved,
child3 resized, Rectangle {0, 301, 466, 128}
ccc moved,
ccc resized, Rectangle {5, 5, 456, 118}
ddd moved,
ddd resized, Rectangle {5, 5, 442, 104}
table moved: Rectangle {5, 5, 442, 104}
table resized: Rectangle {5, 5, 442, 104}
table resized: Rectangle {5, 5, 428, 90}
shell resized, table bound: Rectangle {5, 5, 428, 90}
shell moved,
shell moved,
shell moved,
shell moved,
shell resized, table bound: Rectangle {5, 5, 428, 90}
child3 moved,
child3 resized, Rectangle {0, 475, 998, 202}
ccc resized, Rectangle {5, 5, 988, 192}
ddd resized, Rectangle {5, 5, 974, 178}
table resized: Rectangle {5, 5, 974, 178}
table resized: Rectangle {5, 5, 960, 164}
shell moved,
shell resized, table bound: Rectangle {5, 5, 960, 164}
shell moved,
shell resized, table bound: Rectangle {5, 5, 960, 164}
shell moved,
shell resized, table bound: Rectangle {5, 5, 960, 164}
child3 moved,
child3 resized, Rectangle {0, 301, 466, 128}
ccc resized, Rectangle {5, 5, 456, 118}
ddd resized, Rectangle {5, 5, 442, 104}
table resized: Rectangle {5, 5, 442, 104}
table resized: Rectangle {5, 5, 428, 90}

7.Re:请教一个关于SashFORM的问题!请各位帮忙! [Re: liankun] Copy to clipboard
Posted by: liankun
Posted on: 2004-11-01 15:28

TO:xiaomage234

该表格在双击SHELL最大化的时候或拖动SHELL的时候,刷新异常:
异常表现为:表格没有撑满父Composite,而拖动SASHFORM中的风格条表格则可以撑满父Composite,

或者你可以试一下把表格的父COMPOSITE少套一层,就可以看到SHELL Resize的时候表格可以正常撑满,而多了一层COMPOSITE,表格就无法在SHELL RESIZE的时候正常撑满,即表现为刷新异常!!

8.Re:请教一个关于SashFORM的问题!请各位帮忙! [Re: liankun] Copy to clipboard
Posted by: liankun
Posted on: 2004-11-01 15:29

程序本身没有抛出异常,,呵呵,,误导大家了,

应该是刷新出异常!

9.Re:请教一个关于SashFORM的问题!请各位帮忙! [Re: liankun] Copy to clipboard
Posted by: xiaomage234
Posted on: 2004-11-01 17:50

我这刷新也没出异常啊~

运行正常

10.Re:请教一个关于SashFORM的问题!请各位帮忙! [Re: liankun] Copy to clipboard
Posted by: liankun
Posted on: 2004-11-02 10:51

你是在WIN2000下跑的么?我在WIN2000下面确实出现这个TABLE没有填满COMPOSITE .

另外,请看这个测试程序,


/*
* Created on 2004-11-2
*
*/
package org.jeff.swt;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

/**
* @author JeffLian.
*
*/
public class T10 {

public static void main(String[] args) {
//create shell
final Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new FillLayout());

//create content
Composite content = new Composite(shell, SWT.NONE);
content.setLayout(new FillLayout());

/**---------------------------------------------
* add child composite
* When the variable "len" less than 11, the Button will show normal
*
* Can anyone tell me that whether or not the nested composite have the number limit ?
* and how to avoid this problem ?
*
---------------------------------------------*/
int len = 11;
Composite kk = new Composite(content, SWT.BORDER);
kk.setLayout(new FillLayout());
for(int i=0; i< len ;i++ ){
kk = new Composite(kk, SWT.BORDER);
kk.setLayout(new FillLayout());
}

new Button(kk,SWT.PUSH).setText("BUTTON");


shell.setBounds(20, 30, 500, 500);
shell.open();
while (!shell.isDisposed()){
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();

}
}


11.Re:请教一个关于SashFORM的问题!请各位帮忙! [Re: liankun] Copy to clipboard
Posted by: liankun
Posted on: 2004-11-02 10:52

len = 11的时候
BUTTON根本就无法显示出来,

而只有LEN <11的时候,BUTTON才可以正常的显示出来!

12.Re:请教一个关于SashFORM的问题!请各位帮忙! [Re: liankun] Copy to clipboard
Posted by: xiaomage234
Posted on: 2004-11-02 16:28

呵呵,挺过瘾的~

我的到len=21都没事,不过到22的时候就不行了,终于看到你说的效果了!!!

可能跟IDE 有关系吧

我用的是eclipse3.0

os也是win2k
不过这种现象是像你说的刷新有问题,如果你拖到最大化的话,还是没问题的~

13.Re:请教一个关于SashFORM的问题!请各位帮忙! [Re: liankun] Copy to clipboard
Posted by: liankun
Posted on: 2004-11-04 10:21

你的SWT DLL是什么版本?

我在使用LEN = 11 的时候,按钮无法出来了,最大化窗口也没有作用的!

14.Re:请教一个关于SashFORM的问题!请各位帮忙! [Re: liankun] Copy to clipboard
Posted by: xiaomage234
Posted on: 2004-11-08 17:24

swt-win32-3062.dll

eclipse3.0.0里带的


   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