Be sure your post includes:
1.SmartGWT: 3.0
2. browser(s) and version(s) involved
-- Firefox 7.0.1
I am creating a GUI grid of numbers (for example: representing minutes-in-an-hour of 10X6). I am adding a Label widget for each grid cell, as per the below code.
In the click handler for each cell, I want to toggle the background color of the clicked cell to gray / white.
for this:
1. I tried using getBackgroundColor() method on the label, but it always gives null, even if I set the value via setBackgroundColor("gray").
2. I tried using Label.setProperty("selected", true); But there is no method available to retrieve the property such as getProperty on a label widget.
2nd method won't obviously work, bcoz there is no getProperty available.
For the 1st method, the getBackgroundColor() always returns null.
thanks to anyone helping me on getting this right.
1.SmartGWT: 3.0
2. browser(s) and version(s) involved
-- Firefox 7.0.1
I am creating a GUI grid of numbers (for example: representing minutes-in-an-hour of 10X6). I am adding a Label widget for each grid cell, as per the below code.
Code:
package com.rv.gwtsample.client; import com.google.gwt.core.client.GWT; import com.smartgwt.client.types.Alignment; import com.smartgwt.client.types.Overflow; import com.smartgwt.client.util.SC; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.Label; import com.smartgwt.client.widgets.WidgetCanvas; import com.smartgwt.client.widgets.events.ClickEvent; import com.smartgwt.client.widgets.events.ClickHandler; import com.smartgwt.client.widgets.layout.HLayout; import com.smartgwt.client.widgets.layout.VLayout; import com.smartgwt.client.widgets.tile.TileLayout; public class MinutesGrid extends VLayout { private int numCols = 10; public MinutesGrid() { final int CELL_WIDTH = 22; final int CELL_HEIGHT = 22; int numRows = 60 / numCols; for (int row = 0; row < numRows; ++row) { HLayout layout = new HLayout(); for (int col = 0; col < numCols; ++col) { final Label lbl = new Label(Integer.toString((row * numCols) + col)); lbl.setOverflow(Overflow.HIDDEN); lbl.setWidth(CELL_WIDTH); lbl.setHeight(CELL_HEIGHT); lbl.setAlign(Alignment.CENTER); // lbl.setStyleName("gridLabel"); lbl.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { String bgColor =null; if ((bgColor=lbl.getBackgroundColor())== null || bgColor.equals("white")) { lbl.setBackgroundColor("gray"); } else { lbl.setBackgroundColor("white"); } GWT.log(lbl.getBackgroundColor()); SC.say("You clicked on [" + lbl.getContents() + "]"); } }); layout.addMember(lbl); } this.addMember(layout); } this.setWidth(CELL_WIDTH * numCols); this.setHeight(CELL_HEIGHT * numRows); } }
for this:
1. I tried using getBackgroundColor() method on the label, but it always gives null, even if I set the value via setBackgroundColor("gray").
2. I tried using Label.setProperty("selected", true); But there is no method available to retrieve the property such as getProperty on a label widget.
2nd method won't obviously work, bcoz there is no getProperty available.
For the 1st method, the getBackgroundColor() always returns null.
thanks to anyone helping me on getting this right.
Comment