• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:JButtonの描画
#navi(../)
RIGHT:Posted by [[terai]] at 2009-08-24
*JButtonの描画 [#b1486d31]
JButtonの状態描画をテストします。

-&jnlp;
-&jar;
-&zip;

#screenshot

**サンプルコード [#l599c4e7]
#code{{
java.util.List<JCheckBox> clist = Arrays.asList(
  new JCheckBox(new AbstractAction("setFocusPainted") {
    public void actionPerformed(ActionEvent e) {
      boolean flg = ((JCheckBox)e.getSource()).isSelected();
      for(JButton b:list) b.setFocusPainted(flg);
      p.revalidate();
    }
  }),
  new JCheckBox(new AbstractAction("setBorderPainted") {
    public void actionPerformed(ActionEvent e) {
      boolean flg = ((JCheckBox)e.getSource()).isSelected();
      for(JButton b:list) b.setBorderPainted(flg);
      p.revalidate();
    }
  }),
  new JCheckBox(new AbstractAction("setContentAreaFilled") {
    public void actionPerformed(ActionEvent e) {
      boolean flg = ((JCheckBox)e.getSource()).isSelected();
      for(JButton b:list) b.setContentAreaFilled(flg);
      p.revalidate();
    }
  }),
  new JCheckBox(new AbstractAction("setRolloverEnabled") {
    public void actionPerformed(ActionEvent e) {
      boolean flg = ((JCheckBox)e.getSource()).isSelected();
      for(JButton b:list) b.setRolloverEnabled(flg);
      p.revalidate();
    }
  })
);
}}

**解説 [#ua38e7ee]
上記のサンプルでは、JButtonの状態(たとえばフォーカスの有無を描画するか?など)をテストします。これらはLook & Feelによって効果が異なる場合があるようです。

- [http://java.sun.com/javase/ja/6/docs/ja/api/javax/swing/AbstractButton.html#setFocusPainted(boolean) setFocusPainted]
- [http://java.sun.com/javase/ja/6/docs/ja/api/javax/swing/AbstractButton.html#setBorderPainted(boolean) setBorderPainted]
- [http://java.sun.com/javase/ja/6/docs/ja/api/javax/swing/AbstractButton.html#setContentAreaFilled(boolean) setContentAreaFilled]
- [http://java.sun.com/javase/ja/6/docs/ja/api/javax/swing/AbstractButton.html#setRolloverEnabled(boolean) setRolloverEnabled]

//**参考リンク
**コメント [#u75fef0a]
#comment