Reputation: 6153
I have a class that extends the smartgwt ImgButton. When the Button is pressed a popup should be shown that contains further buttons. The buttons in this popup should not be rendered like common buttons, but rather like text links - so I applied a custom CSS class. Everything works fine so far. But when I press any of the buttons in the popup, the background of the button gets transparent and the text behind the popup shines through. This is ugly, but I can't find a way to solve this.
Does anyone have an idea how to keep the background color when the button is pressed?
Here is the code:
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.widgets.ImgButton;
import com.smartgwt.client.widgets.Button;
import com.smartgwt.client.widgets.events.ClickEvent;
import com.smartgwt.client.widgets.events.ClickHandler;
public class MultiButton extends ImgButton {
private PopupPanel popup;
private VerticalPanel content;
public MultiButton() {
super();
popup = new PopupPanel();
popup.setAnimationEnabled(true);
popup.setAutoHideEnabled(true);
content = new VerticalPanel();
popup.add(content);
this.setWidth(18);
this.setHeight(18);
this.setShowRollOver(false);
this.setShowDown(false);
this.setSrc("person.png");
this.addClickHandler(new ClickHandler() {
@Override
public void onClick(final ClickEvent event) {
popup.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
@Override
public void setPosition(int offsetWidth, int offsetHeight) {
int left = event.getX() + 7;
int top = event.getY() + 7;
popup.setPopupPosition(left, top);
}
});
}
});
}
public void addMultiButtonEntry(String name, ClickHandler handler) {
Button b = new Button(popup.getStyleName());
b.addClickHandler(handler);
b.setShowHover(false);
b.setShowRollOver(false);
b.setBaseStyle("nt-multibutton-button");
b.setAlign(Alignment.LEFT);
content.add(b);
}
}
and this is the CSS definition:
.nt-multibutton-button {
border: 0px !important;
color: #657380;
font-size: 11px;
font-weight: bold;
text-align: left;
padding-left: 5px;
width:90%;
background-color: white;
}
Thank you for every hint!
PS: I know it isn't good style to mix SmartGWT and GWT components, but I didn't find a PopUp in SmartGWT and I don't want to code my own.
Upvotes: 0
Views: 5259
Reputation: 6153
I just found out how to do it.
I added a style primary name and the style name to the buttons and now it works :)
So the buttons for the popup are now created as follows:
Button b = new Button(name);
b.addClickHandler(handler);
b.setShowHover(false);
b.setShowRollOver(false);
String css = "nt-multibutton-button";
b.setStylePrimaryName(css);
b.setBaseStyle(css);
b.setStyleName(css);
b.setAlign(Alignment.LEFT);
content.add(b);
Upvotes: 3