java GWT Horizo​​ntalPanel setSpacing?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3030731/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 00:01:32  来源:igfitidea点击:

GWT HorizontalPanel setSpacing?

javacssgwtpadding

提问by aadidasu

Is there a way to set padding on GWT's HorizontalPanel?

有没有办法在 GWT 上设置填充HorizontalPanel

I wanted to just have 20px left padding and then add few buttons.
Currently I can only add setSpacing()and that puts padding on top, left, right and bottom.

我只想有 20 像素的左填充,然后添加几个按钮。
目前我只能添加setSpacing()并在顶部、左侧、右侧和底部放置填充。

回答by Igor Klimer

You could (and should) use CSS for this, something like:

您可以(并且应该)为此使用 CSS,例如:

.paddedHorizontalPanel {
    padding-left: 20px;
}

And if you want every Buttonin that HorizontalPanelto be 20pxapart, then you can try this instead:

如果你想每一个ButtonHorizontalPanel20px分开,那么你可以试试这个:

.paddedHorizontalPanel .gwt-Button {
    margin-left: 20px;
}

And then add this style to you HorizontalPanelvia hPanel.addStyleName("paddedHorizontalPanel");More on CSS and GWT in the docs.

然后HorizontalPanel通过文档hPanel.addStyleName("paddedHorizontalPanel");More on CSS 和 GWT添加此样式。

PS: AFAIK, not including setPadding was a concious choice on part of the GWT team - they wanted to leave the styling of the application entirely up to CSS.

PS:AFAIK,不包括 setPadding 是 GWT 团队的一个有意识的选择 - 他们希望将应用程序的样式完全留给 CSS。

回答by davgut

In worst case you can always do :

在最坏的情况下,您始终可以执行以下操作:

HorizontalPanel p = new HorizontalPanel();
p.getElement().getStyle().setPadding(20, Unit.PX);