开发者

Is there a way to make a Google Web Toolkit (GWT) Button look like a HTML Hyperlink?

开发者 https://www.devze.com 2022-12-23 08:22 出处:网络
I plan on appending some comments onto a text, to do that, first, I need the concerned text to act like a button for me to launch a popup, which in turn shows the comment. For that to happen, I need t

I plan on appending some comments onto a text, to do that, first, I need the concerned text to act like a button for me to launch a popup, which in turn shows the comment. For that to happen, I need to make that concerned text to act like a button in GWT, but due to some aesthetic reasons I don't want it to look like a normal GWT Button, instead, I prefer it to look like any normal HTML hyper-link, which upon clicking it, acts exactly like a GWT Button whi开发者_如何学编程ch in turn showing the comment in the pop up. So is there a way to make a GWT Button appear more like a html hyper-link? Or, at the minimum, would it be possible to convert the concerned text to .JPG for it to be inserted into a Image Button in GWT?


What you are probably looking for is an Anchor (heh, that was straightforward ;)). It implements the HasClickHandlers interface, so you can add a ClickHandler like such:

Anchor a = new Anchor("This is some text", false); // Set to true if the text contains HTML tags
a.addClickHandler(new ClickHandler() {
    onClick(ClickEvent event) {
        //Do some stuff
    }
});

Update:
A different solution is to use a FocusPanel - the advantage is that FocusPanel is a SimplePanel, meaning you can put another panel in it, which should make it easier to put other GWT Widgets in it (in case you wanted something more than just plain text in the clickable area - of course you can put any HTML in the Anchor, but my way is less 'hacky' IMHO).

HorizontalPanel hPanel = new HorizontalPanel();
hPanel.add(new Image("images/img.png"));
hPanel.add(new Label("Some text"));

FocusPanel focusPanel = new FocusPanel(hPanel);
focusPanel.addClickHandler(new ClickHandler() {
    onClick(ClickEvent event) {
        //Event fired when clicked anywhere in the hPanel - meaning the image and label
        //Do some stuff, maybe show a PopupPanel
    }
});

BTW, if you need a popup, check out the PopupPanel widget.


Now, I'm not intimately familiar with GWT, but presumably the way the GWT button works is that it fires an event that shows the popup (actually I'm fairly certain this is how it's done).

If you dig a little in the GWT button code you should not have any problems of attaching a similar event-handlar to a normal <a>.


I'd never work with GWT but when you have something on a webpage, you can change the facde of control with CSS in a manner which nobody can guess what you used.

I suggest to use following css code block, and tell me was it good for you or not

#GWTButtonToLinkConverter
{
backgound-color: Transparent;
border: 0px;
border-collapse: collapse;
color: blue;
text-decoration: underline;
padding: 0px;
margin : 0px;
}
0

精彩评论

暂无评论...
验证码 换一张
取 消