简体   繁体   中英

To know the type of widget in horizontal panel in gwt

I have a GWT project. I am using a getWidget() method on a horizontal panel and I want to know the type of widget returned by this method. Whether the returned widget is a button or a textbox (as I would have put only these 2 kinds of widget into my horizontal panel initially).

For example:

HorizontalPanel x;
X.getWidget(4);

I want to know the type of the widget returned.

Is there any method for this?

You can check the returned widget with instanceof

Example:

final Widget widget = horizontalPanel.getWidget(0);
if (widget instanceof Button) {
    System.out.println("It's a button!");
} else if (widget instanceof TextBox) {
    System.out.println("It's a textbox!");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM