PDA

View Full Version : Buttons with icons in ColumnConfigs



Pandaman
17 Jul 2009, 7:43 AM
I am having trouble rendering Button widgets with icons in ColumnConfigs; the image overlaps the text in the button when the button is in a column config header (instead of being aligned as set by IconAlign). Here's a test that illustrates this (assuming you have the jpg I attached in the same directory as this java file). Be sure to import com.google.gwt.user.client.ui.ImageBundle, com.google.gwt.user.client.ui.AbstractImagePrototype, and com.google.gwt.core.client.GWT along with the ext-gwt imports.


private static final PnlImageBundle ICONS = GWT.create(PnlImageBundle.class);

public void onModuleLoad() {
Viewport viewport = new Viewport();
viewport.add(testButtonColumns());
RootPanel.get().add(viewport);
}

private TreeGrid<BaseModel> testButtonColumns() {

final ArrayList<ColumnConfig> columns = new ArrayList<ColumnConfig>();
final ColumnConfig treeColumn = new ColumnConfig("name","name", 150);

addButtonToCol(treeColumn);

treeColumn.setRenderer(new TreeGridCellRenderer<BaseModel>());
columns.add(treeColumn);
columns.add(new ColumnConfig("details","details", 150));
final ColumnModel cm = new ColumnModel(columns);

final TreeStore<BaseModel> treeStore = new TreeStore<BaseModel>();
addDummyData(0, treeStore);
addDummyData(1, treeStore);
addDummyData(2, treeStore);

final TreeGrid<BaseModel> treeGrid = new TreeGrid<BaseModel>(treeStore, cm);
treeGrid.setAutoHeight(true);

return treeGrid;
}

private static void addButtonToCol(final ColumnConfig column) {
final Button openChartButton = new Button();
openChartButton.setIconAlign(IconAlign.LEFT);
openChartButton.setScale(ButtonScale.MEDIUM);
openChartButton.setIcon(ICONS.getChartIcon());
openChartButton.setText(column.getHeader());

column.setWidget(openChartButton, column.getHeader());
column.setHeader(column.getHeader());
}

public interface PnlImageBundle extends ImageBundle {

@Resource("pie_chart_icon.jpg")
AbstractImagePrototype getChartIcon();
}Does anyone know why the Icon alignment is messed up?

Pandaman
22 Jul 2009, 7:03 AM
Any ideas? Is this a bug?