- GWT 教程
- GWT - 首頁
- GWT - 概述
- GWT - 環境設定
- GWT - 應用程式
- GWT - 建立應用程式
- GWT - 部署應用程式
- GWT - 使用 CSS 樣式
- GWT - 基本控制元件
- GWT - 表單控制元件
- GWT - 複雜控制元件
- GWT - 佈局面板
- GWT - 事件處理
- GWT - 自定義控制元件
- GWT - UIBinder
- GWT - RPC 通訊
- GWT - JUnit 整合
- GWT - 除錯應用程式
- GWT - 國際化
- GWT - History 類
- GWT - 書籤支援
- GWT - 日誌框架
- GWT 有用資源
- GWT - 問答
- GWT - 快速指南
- GWT - 有用資源
- GWT - 討論
GWT - 垂直面板控制元件
簡介
VerticalPanel 控制元件表示一個面板,該面板將其所有控制元件都以單列垂直方式佈局。
類宣告
以下是 com.google.gwt.user.client.ui.VerticalPanel 類的宣告:
public class VerticalPanel
extends CellPanel
implements HasAlignment, InsertPanel.ForIsWidget
類建構函式
| 序號 | 建構函式 & 描述 |
|---|---|
| 1 |
VerticalPanel() 空垂直面板的建構函式。 |
類方法
| 序號 | 函式名稱 & 描述 |
|---|---|
| 1 |
void add(Widget w) 新增子控制元件。 |
| 2 |
具有水平對齊方式。水平對齊常量 getHorizontalAlignment() 獲取水平對齊方式。 |
| 3 |
具有垂直對齊方式。垂直對齊常量 getVerticalAlignment() 獲取垂直對齊方式。 |
| 4 |
void insert(IsWidget w, int beforeIndex) |
| 5 |
void insert(Widget w, int beforeIndex) 在指定索引之前插入子控制元件。 |
| 6 |
protected void onEnsureDebugId(java.lang.String baseID) 受影響的元素: -# = 給定索引處的單元格。 |
| 7 |
boolean remove(Widget w) 移除子控制元件。 |
| 8 |
void setHorizontalAlignment(HasHorizontalAlignment.HorizontalAlignmentConstant align) 設定要用於新增到此面板的控制元件的預設水平對齊方式。 |
| 9 |
void setVerticalAlignment(HasVerticalAlignment.VerticalAlignmentConstant align) 設定要用於新增到此面板的控制元件的預設垂直對齊方式。 |
繼承的方法
此類繼承自以下類的方法:
com.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.Widget
com.google.gwt.user.client.ui.Panel
com.google.gwt.user.client.ui.ComplexPanel
com.google.gwt.user.client.ui.CellPanel
java.lang.Object
VerticalPanel 控制元件示例
此示例將引導您完成簡單的步驟,以展示如何在 GWT 中使用 VerticalPanel 控制元件。請按照以下步驟更新我們在GWT - 建立應用程式章節中建立的 GWT 應用程式:
| 步驟 | 描述 |
|---|---|
| 1 | 在com.tutorialspoint包下建立一個名為HelloWorld的專案,如GWT - 建立應用程式章節中所述。 |
| 2 | 修改HelloWorld.gwt.xml、HelloWorld.css、HelloWorld.html和HelloWorld.java,如下所述。保持其餘檔案不變。 |
| 3 | 編譯並執行應用程式以驗證已實現邏輯的結果。 |
以下是修改後的模組描述符src/com.tutorialspoint/HelloWorld.gwt.xml的內容。
<?xml version = "1.0" encoding = "UTF-8"?> <module rename-to = 'helloworld'> <!-- Inherit the core Web Toolkit stuff. --> <inherits name = 'com.google.gwt.user.User'/> <!-- Inherit the default GWT style sheet. --> <inherits name = 'com.google.gwt.user.theme.clean.Clean'/> <!-- Specify the app entry point class. --> <entry-point class = 'com.tutorialspoint.client.HelloWorld'/> <!-- Specify the paths for translatable code --> <source path = 'client'/> <source path = 'shared'/> </module>
以下是修改後的樣式表文件war/HelloWorld.css的內容。
body {
text-align: center;
font-family: verdana, sans-serif;
}
h1 {
font-size: 2em;
font-weight: bold;
color: #777777;
margin: 40px 0px 70px;
text-align: center;
}
.gwt-CheckBox {
margin: 10px;
}
以下是修改後的 HTML 宿主檔案war/HelloWorld.html的內容。
<html>
<head>
<title>Hello World</title>
<link rel = "stylesheet" href = "HelloWorld.css"/>
<script language = "javascript" src = "helloworld/helloworld.nocache.js">
</script>
</head>
<body>
<h1>VerticalPanel Widget Demonstration</h1>
<div id = "gwtContainer"></div>
</body>
</html>
讓我們使用以下 Java 檔案src/com.tutorialspoint/HelloWorld.java的內容,它將演示 VerticalPanel 控制元件的使用。
package com.tutorialspoint.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.CheckBox;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.RootPanel;
public class HelloWorld implements EntryPoint {
public void onModuleLoad() {
// Create a vertical panel
VerticalPanel verticalPanel = new VerticalPanel();
// Add CheckBoxes to vertical Panel
for(int i = 1; i <= 10; i++){
CheckBox checkBox = new CheckBox("Item" + i);
verticalPanel.add(checkBox);
}
DecoratorPanel decoratorPanel = new DecoratorPanel();
decoratorPanel.add(verticalPanel);
// Add the widgets to the root panel.
RootPanel.get().add(decoratorPanel);
}
}
完成所有更改後,讓我們像在GWT - 建立應用程式章節中一樣,在開發模式下編譯並執行應用程式。如果您的應用程式一切正常,則會產生以下結果: