TITLE:JButtonの描画
Posted by aterai at 2009-08-24

JButtonの描画

JButtonの状態描画をテストします。
  • category: swing folder: ButtonPainted title: JButtonの描画 tags: [JButton, Focus, Icon] author: aterai pubdate: 2009-08-24T12:58:07+09:00 description: JButtonの設定を変更し、コンテンツ領域、フチ、フォーカスやロールオーバー状態がどう描画されるかをテストします。 image: https://lh3.googleusercontent.com/_9Z4BYR88imo/TQTIWYXt9eI/AAAAAAAAASo/se2OKkQA83U/s800/ButtonPainted.png

概要

JButtonの設定を変更し、コンテンツ領域、フチ、フォーカスやロールオーバー状態がどう描画されるかをテストします。
ButtonPainted.png

サンプルコード

#spanend
#spandel
java.util.List<JCheckBox> clist = Arrays.asList(
#spanend
#spanadd
* サンプルコード [#sourcecode]
#spanend
#spanadd
#code(link){{
#spanend
#spanadd
List<JCheckBox> clist = Arrays.asList(
#spanend
  new JCheckBox(new AbstractAction("setFocusPainted") {
    public void actionPerformed(ActionEvent e) {
      boolean flg = ((JCheckBox)e.getSource()).isSelected();
      for(JButton b:list) b.setFocusPainted(flg);
    @Override 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);
    @Override 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);
    @Override 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);
    @Override public void actionPerformed(ActionEvent e) {
      boolean flg = ((JCheckBox) e.getSource()).isSelected();
      for (JButton b: list) {
        b.setRolloverEnabled(flg);
      }
      p.revalidate();
    }
  })
);

解説

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

解説

上記のサンプルでは、フォーカスの有無を表示するかなどの設定を切り替えてJButtonの描画をテストしています。これらはLook & Feelに依存しそれぞれ有効か無効かなどが異なります。

コメント

参考リンク

コメント