熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

開發Eclipse下的自定義控件[6]

2013-11-23 20:43:57  來源: Java開源技術 

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));

  以上我們介紹了如何開發一個簡單的自定義控件所需要涉及的技術這裡我們只以一個簡單的顏色控件為例但是一旦我們掌握了方法我們很容易就可以開發出各種不同的漂亮控件

[]  []  []  []  []  []  


From:http://tw.wingwit.com/Article/program/Java/ky/201311/28981.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.