如何使用 GWT 2.4 对带有边框的小部件进行垂直布局?

发布于 2024-12-17 18:46:50 字数 2203 浏览 0 评论 0原文

我正在使用 GWT 2.4 和 uiBinder。

我试图在页面中心获得一组与单个外边框垂直对齐的小部件。我认为这相当容易,但我需要在页面中心使用垂直布局来对齐小部件。

小部件按照我想要使用垂直面板的方式排列,但没有可用的边框选项,除非我想使用 borderwidth 属性在每个元素周围放置边框。

这是 uiBinder 代码:

<g:HTMLPanel ui:field="mainPanel">
         <g:VerticalPanel ui:field="verticalPanel" styleName="{style.center}">
                        <g:Label ui:field="titleLabel"></g:Label>
                        <g:Label ui:field="loggedInUserLabel" text="You are logged in as: "> </g:Label>
                        <g:Label ui:field="userNameLabel" styleName="{style.spacer-bottom}"></g:Label>

                        <g:FormPanel ui:field="formPanel" styleName="{style.spacer-bottom}">
                        <g:FileUpload ui:field="fileUpload"></g:FileUpload>
                        </g:FormPanel>

                        <g:Label ui:field="Label" text="Please select:"></g:Label> 

                        <g:ListBox ui:field="ListBox" styleName="{style.spacer-bottom}" visibleItemCount='5'> 
                            <g:item value="-1">-- Please select item(s) below: --</g:item>
                        </g:ListBox>

                        <g:Button ui:field="Button" styleName="{style.button}" text="Calculate"></g:Button> 

                        <g:HorizontalPanel ui:field="horizontalPanel"  styleName="{style.spacer-top}">
                            <g:cell width='5em' horizontalAlignment="ALIGN_LEFT">
                                <g:Button ui:field="cancelButton" styleName="{style.exitcancelbutton}"  text="Cancel"></g:Button>
                            </g:cell>
                            <g:cell width='5em' horizontalAlignment="ALIGN_RIGHT">
                                <g:Button ui:field="exitButton" styleName="{style.exitcancelbutton}" text="Exit"></g:Button>
                            </g:cell>                   
                        </g:HorizontalPanel>
                </g:VerticalPanel>
    </g:HTMLPanel>

我是否设计错误,我的意思是使用错误的面板来实现我想要做的事情?

I'm using GWT 2.4 and uiBinder.

I'm trying to get a grouping of widgets in the center of a page aligned vertically with a single outside border. I thought it would be fairly easy, but I need to use a vertical layout in the center of the page to align the widgets.

The widgets are lined up the way I wanted using Vertical Panels, but there isn't a border option available, unless I want to put borders around each of the elements using the borderwidth property.

Here is the uiBinder code:

<g:HTMLPanel ui:field="mainPanel">
         <g:VerticalPanel ui:field="verticalPanel" styleName="{style.center}">
                        <g:Label ui:field="titleLabel"></g:Label>
                        <g:Label ui:field="loggedInUserLabel" text="You are logged in as: "> </g:Label>
                        <g:Label ui:field="userNameLabel" styleName="{style.spacer-bottom}"></g:Label>

                        <g:FormPanel ui:field="formPanel" styleName="{style.spacer-bottom}">
                        <g:FileUpload ui:field="fileUpload"></g:FileUpload>
                        </g:FormPanel>

                        <g:Label ui:field="Label" text="Please select:"></g:Label> 

                        <g:ListBox ui:field="ListBox" styleName="{style.spacer-bottom}" visibleItemCount='5'> 
                            <g:item value="-1">-- Please select item(s) below: --</g:item>
                        </g:ListBox>

                        <g:Button ui:field="Button" styleName="{style.button}" text="Calculate"></g:Button> 

                        <g:HorizontalPanel ui:field="horizontalPanel"  styleName="{style.spacer-top}">
                            <g:cell width='5em' horizontalAlignment="ALIGN_LEFT">
                                <g:Button ui:field="cancelButton" styleName="{style.exitcancelbutton}"  text="Cancel"></g:Button>
                            </g:cell>
                            <g:cell width='5em' horizontalAlignment="ALIGN_RIGHT">
                                <g:Button ui:field="exitButton" styleName="{style.exitcancelbutton}" text="Exit"></g:Button>
                            </g:cell>                   
                        </g:HorizontalPanel>
                </g:VerticalPanel>
    </g:HTMLPanel>

Did I design this wrong, I mean using the wrong panel, for what I'm trying to do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

诺曦 2024-12-24 18:46:50

您可以为垂直面板的 borderwidth 设置边框,以便添加到其中的所有小部件都将显示为好像有边框一样。

you can set the border for borderwidth of the verticalpanel so that all the widgets added to it will be shown as if it had a border.

惟欲睡 2024-12-24 18:46:50

好吧,这个问题是我自己想出来的。作为一名 java 开发人员,我需要更多地依赖 CSS 解决方案,但经过一番思考后,CSS 是实现此目的的正确方法。我将其放入我的 CSS 中:

.mainPanel {
            width: 400px ;
            margin-left: auto ;
            margin-right: auto ;
            border: 1px solid black;
            padding: 2px;
            margin-bottom:6px;
        }

然后我利用最上面的面板,这是我的主容器(HTMLPanel),并将样式应用于它:

<g:HTMLPanel ui:field="mainPanel" styleName="{style.mainPanel}">
            <table width="30%" align="center">
                <tr> etc...

它位于页面的中心,并具有我想要的边框。我通常出于习惯而倾向于表格布局,但它似乎很适合我想要的东西。

Okay, I figured this one out on my own. Being a java dev I need to lean more on the CSS solutions, but after doing some thinking, CSS is the correct way to do this. I put this into my CSS:

.mainPanel {
            width: 400px ;
            margin-left: auto ;
            margin-right: auto ;
            border: 1px solid black;
            padding: 2px;
            margin-bottom:6px;
        }

and then I leverage the topmost panel, which is my main container, (the HTMLPanel) and apply the style to it:

<g:HTMLPanel ui:field="mainPanel" styleName="{style.mainPanel}">
            <table width="30%" align="center">
                <tr> etc...

It's centered in the page and has a border like I wanted. I generally lean towards the table layouts out of habit, but it seems to work well for what I want here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文