ImageButton in gwt - gwt

I have to create a image button in gwt which uses three images(left side image,center stretch image and right image).Left side images and right images having rounded corners.Center Image wants to be stretched depends on button title size.Created ImageButton should have all the functionalities of Button.
Can anyone help me in how to achieve this.

If you need a button with rounded corners then there are a number of options:
Create a new widget that extends the DecoratorPanel to create the rounded corners. The DecoratorPanel will result in a table (HTML). You'll probably want to replace the standard images. Look at the standard.css that GWT provides to find the styles that define those images, then override those styles in your custom stylesheet (look for the CSS class ".gwt-DecoratorPanel"). In the widget, add a Label widget to display the button text and provide get and set methods on your widget to get and set text to the internal label. The label will resize automatically forcing the table cell to grow bigger.
Create a new widget that extends Composite. The widget should wrap a FlexTable. Use 3 cells on the same row. Add a Label to the center cell and provide get and set methods on your widget to get and set text to the internal label. The label will resize automatically forcing the table cell to grow bigger. Add the appropriate handlers to the FlexTable widget. I suggest you use those events to add or remove styles to the appropriate cells and define the background images in a stylesheet.
You could create your own widget. This requires that you generate your own HTML etc. which may not immediately work in every browser. I recommend trying option 1 or 2 first.

You might be able to get away with using only one sprite image if you can limit the maximum width of your buttons. We wrote a CssButton class (extends Button) as part of the GWT Portlets framework that uses a single background image sprite to create rounded buttons. The code uses CSS clipping to select the correct background image from the sprite based on the width of the button.
The main advantages are that it extends the normal GWT Button and uses only a single BUTTON element in the DOM (lightweight). The disadvantage is that the maximum width of the button is limited to the widest button image in the sprite.
It also handles rollover and click effects all using the same sprite.
The code is in the GWT Portlets repository if you want to look further.

Related

How to open Image in full screen when we press on list of image in flutter?

Here I actually use GridView.builder for load list of images. I want to add functionality like when I click on any particular image, it load and open in full screen. How is the possible in flutter?
It may not be the best way but it does the job for me.
Hero widget for multiple network images
The idea is to assign unique hero tags to your images and create a widget for the next screen which dynamically assigns hero tag with the value passed through the constructor. Instead of changing tags for your images, change the tag for the hero widget on the next screen.

Resize the screen in GWT

I am developing a GWT Web application and I would like to include the resize capability into the container. For that, I am implementing a combination of Vertical and Horizontal Panels within a FlowPanel which is resizable. Well, the code for the resize method is the following:
Window.addResizeHandler(new ResizeHandler() {
#Override
public void onResize(ResizeEvent event) {
flowPanel.setHeight(event.getHeight()+"px");
flowPanel.setWidth(event.getWidth()+"px");
}
});
However, when I change the size of the windows, the size of the web elements does not change. Do you know how to implement it?
Thank you very much in advance!!!
You may want to review your layout solution. There are very few cases when you need to use a ResizeHandler. Typically, you can achieve a desired layout either by using a LayoutPanel (or Horizontal/Vertical panels) that automatically resize with the window, or by using CSS. Then your layout will respond well to any changes in a browser window, and you don't need to write any code for that to happen.
EDIT:
In order for a widget to resize automatically, the parent widget must implement ProvidesResize, and the child widget must implement Resizable. FlowPanel does not implement either. Once you use it, the chain of resizing events is broken.
Typically, I use a LayoutPanel for my outmost container. It occupies the entire browser window when added to the RootPanel, and it adjusts with the Window. Vertical and Horizontal panels are similar.
use,
window.getClientWidth();
window.getClientHeight();
Based on your component size you can -/+ px and use.

GWT ScrollPanel with Horizontal SimplePanel

I'm trying to implement a scrollPanel within a Horizontal Panel.
I read this post
GWT Horizontal panel with horizontal scrolling
The answer seems great, however I'm wondering if ravi wrapped his simple panel with a scroll Panel or vice versa.
Basically I wanted to know how the panels were nested within each other?
A scroll panel is nothing special - it's just a DIV element with some CSS set on it. That's what the answer to the other question means, as a SimplePanel is simply a Widget that appears as a DIV.
So what the other answer did was create a scrolling widget by:
Creating a SimplePanel as the content container
Set some CSS with the overflow-x attribute to the SimplePanel
Setting the content will now have a horizontal scroll bar (due to the CSS attribute).
If you prefer a more direct way of doing this check out UiBinder. Using it you can combine widgets/CSS/HTML elements in a form closer to how the browser renders your UI. So for example you can create a DIV with the required CSS to achive a scrolling container.

overlapping widgets gtk

How can i make widgets overlap one another.
Lower most should be image, rest above can be other widgets like buttons.
Subclass the larger(parent) widget. In a create() method or in the constructor, add a layout( or container) widget to the parent widget, then inset the others into the container. Now threat this new subclass as if it were a single, but specialized, version of its super class.
A Window is an example of a parent widget, while Fixed is an example container. A child could be an EventBox enclosing an Image. The composite of all these is a new window object that has pictures that can be clicked.
For the case of a window's titlebar look with a pixmap background, and buttons, try a Window with an Image and a Fixed container to hold the buttons. The Fixed and the Image should be able to overlap as the Fixed is transparent, and an Image has no Window.
If Buttons are truly what's needed, have a look at Button Boxes and Toolbars in the list of GTK Containers. It may be possible to add an Image background to one of those.
A different approach involves an Alignment Widget(from the same list). It specifies where the smaller widgets are positioned and sized in a proportioned manner.
I assumed, OOP, but if it's not, just organize the creation of the widgets from one function. I've made composite widgets functionally in Haskell(Gtk2Hs), and in Guile Gnome Platform (with and without OOP)

How do you get GWT 2.0 to accept clicks on two different Widgets added to a LayoutPanel?

Using GWT 2.0 I have an entry point that adds two Widgets to a LayoutPanel which in turn is added to the RootLayoutPanel. The Widgets both handle click events and have click events registered to them. The problem is that only the last widget added to the LayoutPanel can actually be clicked. Switch the order in which the widgets are added switches the widget that works. Add mroe widgets and still the only you can click is the last one added to the LayoutPanel.
Any idea why this is? Is there any reasoning behind the behaviour, or have I missunderstood what is happening under the covers? How do I gat all widgets in the LayoutPanel to accept events? Should I be using another panel class?
I'm not too bothered if the LayoutPanel prevents anything below it from being clicked, but want all Widgets added to it to be clickable.
Stupid Boy! (said in the voice of Captain Mainwaring)
There is no problem having two Widgets on a LayoutPanel accepting clicks. But if you adjust the Widgets' size by manipulating their elements' styles directly then the containing element created by the LayoutPanel will still cover the whole screen. In effect the last Widget added always covered everything else.
GWT school: D- Must try harder. Easily distracted...