public void getChildCount(AccessibleControlEvent e) {
edetail = colorssize();
}
public void getState(AccessibleControlEvent e) {
int state = ;
int childID = echildID;
if (childID == ACCCHILDID_SELF) {
state = ACCSTATE_NORMAL;
}
else if (childID >= && childID < colorssize()) {
state = ACCSTATE_SELECTABLE;
if (isFocusControl()) {
state |= ACCSTATE_FOCUSABLE;
}
if (rowSel == childID) {
state |= ACCSTATE_SELECTED;
if (isFocusControl()) {
state |= ACCSTATE_FOCUSED;
}
}
}
edetail = state;
}
});
最后我们需要提供一些方法方便程序员使用我们的控件
public void setSelection(int index) {
if (index >= getItemCount() || index < )
return;
oldRowSel = rowSel;
rowSel = index;
selectionChanged();
}
public int getSelectionIndex() {
return rowSel;
}
public int getItemHeight() {
return lineHeight;
}
public void setItemHeight(int height) {
lineHeight = height;
}
public int getItemCount() {
return colorssize();
}
public void add(int colorIndex String colorName) {
colorNamesadd(colorName);
colorsadd(new Integer(colorIndex));
}
我们开发的控件的使用也是非常简单的
CustomList customlist = new CustomList( parent SWTV_SCROLL | SWTH_SCROLL );
customlistadd(SWTCOLOR_BLACKBLACK);
customlistadd(SWTCOLOR_BLUEBLUE);
customlistsetSelection();
customlistsetSize();
customlistsetBackground(DisplaygetDefault()getSystemColor(SWTCOLOR_LIST_BACKGROUND));
以上我们介绍了如何开发一个简单的自定义控件所需要涉及的技术这里我们只以一个简单的颜色控件为例但是一旦我们掌握了方法我们很容易就可以开发出各种不同的漂亮控件
[] [] [] [] [] []