テキストフィールドに背景色を付けてみる

ボタンを押したら背景色が変化するようにしてみる。

アクションにコンポーネントを記述する。

Urumaではウィジット・インジェクションって言ってるやつ

SubDispAction.java

package gui.test;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.seasar.framework.container.annotation.tiger.Component;
import org.seasar.uruma.annotation.EventListener;
import org.seasar.uruma.annotation.Form;

@Component(name="subDispAction")
@Form(SubDispForm.class)
public class SubDispAction {
 public Shell shell;
 public SubDispForm subDispForm;

 public Text title;

 @EventListener(id="button")
 public void dispTitleValue() {
  title.setBackground(new Color(shell.getDisplay(), 255, 255, 80));
  MessageDialog.openInformation(shell, "TitleValue", subDispForm.getTitle());
 }
}

public Text title;がコンポーネントの記述(正確には違うんだろうが・・・。)

title.setBackground(Color color)で背景色を設定できる。

title.setForeground(Color color)で文字の色が設定できる。



この前の記事のフォームを使用しないでテキストフィールドを取得、セットする方法。

public Text title;

 @EventListener(id="button")
 public void dispTitleValue() {
  MessageDialog.openInformation(shell, "TitleValue", title.getText());
  title.setText("てすとだよ(=ω=)");
 }

これでボタンを押下したら入力した内容がダイアログに表示されて、OKを押下すると「てすとだよ(=ω=)」がテキストフィールドにセットされる。

実際フォームを使うのと使わないのどっちがいいんだろう・・・?

まぁフォームは使いまわしできるからそういうときはフォームを使用したほうがいいのかな??