1. 程式人生 > >EAS 分錄預設按鈕隱藏並新增新的按鈕到分錄右側

EAS 分錄預設按鈕隱藏並新增新的按鈕到分錄右側

@Override
public void onLoad() throws Exception {
     // TODO Auto-generated method stub
     super.onLoad();
     kdtEntrys_detailPanel.getAddNewLineButton().setVisible(false);
     kdtEntrys_detailPanel.getInsertLineButton().setVisible(false);
     kdtEntrys_detailPanel.getRemoveLinesButton().setVisible(false);
     addButtonToHMDEntry(kdtEntrys,PCKDButton,180);
     addButtonToHMDEntry(kdtEntrys,btnAdd,86);
     addButtonToHMDEntry(kdtEntrys,btnDel,0);
}
private void addButtonToHMDEntry(KDTable table, KDWorkButton button,int width) {
    	 if (table.getParent() == null || table.getParent().getParent() == null)
    	  return;
    	 // 隱藏按鈕
    	 Component c = table.getParent().getParent();
    	 if (c instanceof DetailPanel) {
    	  JPanel panel = (JPanel) c;
    	  JPanel controlPanel = null;
    	  // 獲取controlPanel
    	  Component[] components = panel.getComponents();
    	  for (int i = 0; i < components.length; i++) {
    	   Component component = components[i];
    	   if ("controlPanel".equals(component.getName())) {
    	    controlPanel = (KDPanel) component;
    	   }
    	  }
    	  // 獲取btn
    	  if (controlPanel != null) {
    	   Rectangle rect = table.getBounds();
    	   int x = rect.width - (button.getWidth() + width);
    	   controlPanel.add(button, new com.kingdee.bos.ctrl.swing.KDLayout.Constraints(x, 3, button.getWidth(), 19, 9));
    	  }
    	 }
    	 
    	}