Gwt-deckpanel-widget

提供:Dev Guides
移動先:案内検索

GWT-DeckPanelウィジェット

前書き

*DeckPanel* ウィジェットは、すべての子ウィジェットを「デッキ」に表示するパネルを表します。一度に表示できるのは1つだけです。 TabPanelによって使用されます。

クラス宣言

以下は com.google.gwt.user.client.ui.DeckPanel クラスの宣言です-

public class DeckPanel
   extends ComplexPanel
      implements HasAnimation, InsertPanel.ForIsWidget

クラスコンストラクター

Sr.No. Constructor & Description
1

DeckPanel()

DeckPanelのコンストラクター。

クラスメソッド

Sr.No. Function name & Description
1

void add(Widget w)

子ウィジェットを追加します。

2

int getVisibleWidget()

現在表示されているウィジェットのインデックスを取得します。

3 *void insert(IsWidget w, int beforeIndex) *
4
  • void insert(Widget w, int beforeIndex)*

指定されたインデックスの前に子ウィジェットを挿入します。

5

boolean isAnimationEnabled()

アニメーションが有効な場合はtrue、有効でない場合はfalseを返します。

6

boolean remove(Widget w)

子ウィジェットを削除します。

7

void setAnimationEnabled(boolean enable)

アニメーションを有効または無効にします。

8

void showWidget(int index)

指定されたインデックスにあるウィジェットを表示します。

継承されるメソッド

このクラスは、次のクラスからメソッドを継承します-

  • 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
  • java.lang.Object

DeckPanelウィジェットの例

この例では、GWTでDeckPanelウィジェットの使用方法を示す簡単な手順を紹介します。 次の手順に従って、_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;
}
.deckpanel {
  border: 1px solid #BBBBBB;
  padding: 3px;
}

以下は、変更された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>DeckPanel Widget Demonstration</h1>
      <div id = "gwtContainer"></div>
   </body>
</html>

DeckPanelウィジェットの使用方法を示すJavaファイル src/com.finddevguides/HelloWorld.java の内容を見てみましょう。

package com.finddevguides.client;


import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DeckPanel;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class HelloWorld implements EntryPoint {

   public void onModuleLoad() {
     //Create DeckPanel widget
      final DeckPanel deckPanel = new DeckPanel();
      deckPanel.setSize("300px", "120px");
      deckPanel.setStyleName("deckpanel");

     //Create lables to add to deckpanel
      Label label1 = new Label("This is first Page");
      Label label2 = new Label("This is second Page");
      Label label3 = new Label("This is third Page");

     //Add labels to deckpanel
      deckPanel.add(label1);
      deckPanel.add(label2);
      deckPanel.add(label3);

     //show first label
      deckPanel.showWidget(0);

     //create button bar
      HorizontalPanel buttonBar = new HorizontalPanel();
      buttonBar.setSpacing(5);

     //create button and add click handlers
     //show different labels on click of different buttons
      Button button1 = new Button("Page 1");
      button1.addClickHandler(new ClickHandler() {
         @Override
         public void onClick(ClickEvent event) {
            deckPanel.showWidget(0);
         }
      });

      Button button2 = new Button("Page 2");
      button2.addClickHandler(new ClickHandler() {
         @Override
         public void onClick(ClickEvent event) {
            deckPanel.showWidget(1);
         }
      });

      Button button3 = new Button("Page 3");
      button3.addClickHandler(new ClickHandler() {
         @Override
         public void onClick(ClickEvent event) {
            deckPanel.showWidget(2);
         }
      });

      buttonBar.add(button1);
      buttonBar.add(button2);
      buttonBar.add(button3);

      VerticalPanel vPanel = new VerticalPanel();
      vPanel.add(deckPanel);
      vPanel.add(buttonBar);

     //Add the widgets to the root panel.
      RootPanel.get().add(vPanel);
   }
}

すべての変更が完了したら、link:/gwt/gwt_create_application [GWT-アプリケーションの作成]の章で行ったように、アプリケーションをコンパイルして開発モードで実行します。 すべてがあなたのアプリケーションでうまくいけば、これは次の結果を生成します-

GWT DeckPanelウィジェット