Gwt-grid-widget
GWT-グリッドウィジェット
前書き
*Grid* ウィジェットは、セル内にテキスト、html、または子ウィジェットを含むことができる長方形のグリッドを表します。 行と列の目的の数に明示的にサイズ変更する必要があります。
クラス宣言
以下は、 com.google.gwt.user.client.ui.Grid クラスの宣言です-
public class Grid
extends HTMLTable
クラスコンストラクター
Sr.No. | Constructor & Description |
---|---|
1 |
Grid() グリッドのコンストラクター。 |
2 |
Grid(int rows, int columns) 要求されたサイズのグリッドのコンストラクター。 |
クラスメソッド
Sr.No. | Function name & Description |
---|---|
1 |
boolean clearCell(int row, int column) 指定したセルの内容を単一のスペースに置き換えます。 |
2 |
protected Element createCell() 新しい空のセルを作成します。 |
3 |
int getCellCount(int row) 列数を返します。 |
4 |
int getColumnCount() このグリッドの列数を取得します。 |
5 |
int getRowCount() 行数を返します。 |
6 |
int insertRow(int beforeRow) テーブルに新しい行を挿入します。 |
7 |
protected void prepareCell(int row, int column) セルがテーブル内の有効なセルであることを確認します。 |
8 |
protected void prepareColumn(int column) 列インデックスが有効であることを確認します。 |
9 |
protected void prepareRow(int row) 行インデックスが有効であることを確認します。 |
10 |
void removeRow(int row) 指定された行をテーブルから削除します。 |
11 |
void resize(int rows, int columns) グリッドのサイズを変更します。 |
12 |
void resizeColumns(int columns) 指定された列数に合わせてグリッドのサイズを変更します。 |
13 |
void resizeRows(int rows) 指定した行数に合わせてグリッドのサイズを変更します。 |
継承されるメソッド
このクラスは、次のクラスからメソッドを継承します-
- 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.HTMLTable
- java.lang.Object
グリッドウィジェットの例
この例では、GWTでのグリッドウィジェットの使用法を示す簡単な手順を紹介します。 次の手順に従って、_GWTで作成したGWTアプリケーションを更新します-アプリケーションの作成_の章-
Step | Description |
---|---|
1 | Create a project with a name HelloWorld under a package com.finddevguides as explained in the GWT - Create Application chapter. |
2 | Modify HelloWorld.gwt.xml, HelloWorld.css, HelloWorldl and HelloWorld.java as explained below. Keep rest of the files unchanged. |
3 | Compile and run the application to verify the result of the implemented logic. |
以下は、変更されたモジュール記述子 src/com.finddevguides/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.finddevguides.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;
}
以下は、変更されたHTMLホストファイル war/HelloWorldl の内容です。
<html>
<head>
<title>Hello World</title>
<link rel = "stylesheet" href = "HelloWorld.css"/>
<script language = "javascript" src = "helloworld/helloworld.nocache.js">
</script>
</head>
<body>
<h1>Grid Widget Demonstration</h1>
<div id = "gwtContainer"></div>
</body>
</html>
グリッドウィジェットの使用方法を示すJavaファイル src/com.finddevguides/HelloWorld.java の内容を見てみましょう。
package com.finddevguides.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.RootPanel;
public class HelloWorld implements EntryPoint {
public void onModuleLoad() {
//Create a grid
Grid grid = new Grid(2, 2);
//Add images to the grid
int numRows = grid.getRowCount();
int numColumns = grid.getColumnCount();
for (int row = 0; row < numRows; row++) {
for (int col = 0; col < numColumns; col++) {
grid.setWidget(row, col,
new Image("http://www.finddevguides.com/images/gwt-mini.png"));
}
}
DecoratorPanel decoratorPanel = new DecoratorPanel();
decoratorPanel.add(grid);
//Add the widgets to the root panel.
RootPanel.get().add(decoratorPanel);
}
}
すべての変更が完了したら、link:/gwt/gwt_create_application [GWT-アプリケーションの作成]の章で行ったように、アプリケーションをコンパイルして開発モードで実行します。 すべてがあなたのアプリケーションでうまくいけば、これは次の結果を生成します-