int (Container container) { if(container==null){ throw new IllegalArgumentException("container cannot be null"); } while(container!=null){ if(container.getLayout() instanceof AbstractLayout){ final AbstractLayout layout=(AbstractLayout)container.getLayout(); if(layout.getHGap()!=-1){ return layout.getHGap(); } } container = container.getParent(); } return DEFAULT_HGAP; }