Swing/ButtonPainted のバックアップの現在との差分(No.5)
- category: swing folder: ButtonPainted title: JButtonの描画 tags: [JButton, Focus, Icon] author: aterai pubdate: 2009-08-24T12:58:07+09:00 description: JButtonの状態描画をテストします。 description: JButtonの設定を変更し、コンテンツ領域、フチ、フォーカスやロールオーバー状態がどう描画されるかをテストします。 image:
概要
JButton
の状態描画をテストします。
概要
JButton
の設定を変更し、コンテンツ領域、フチ、フォーカスやロールオーバー状態がどう描画されるかをテストします。
Screenshot
Advertisement
サンプルコード
サンプルコード
#spandel
java.util.List<JCheckBox> clist = Arrays.asList(
#spanend
#spanadd
List<JCheckBox> clist = Arrays.asList(
#spanend
new JCheckBox(new AbstractAction("setFocusPainted") {
@Override public void actionPerformed(ActionEvent e) {
boolean flg = ((JCheckBox)e.getSource()).isSelected();
for(JButton b:list) b.setFocusPainted(flg);
boolean flg = ((JCheckBox) e.getSource()).isSelected();
for (JButton b: list) {
b.setFocusPainted(flg);
}
p.revalidate();
}
}),
new JCheckBox(new AbstractAction("setBorderPainted") {
@Override public void actionPerformed(ActionEvent e) {
boolean flg = ((JCheckBox)e.getSource()).isSelected();
for(JButton b:list) b.setBorderPainted(flg);
boolean flg = ((JCheckBox) e.getSource()).isSelected();
for (JButton b: list) {
b.setBorderPainted(flg);
}
p.revalidate();
}
}),
new JCheckBox(new AbstractAction("setContentAreaFilled") {
@Override public void actionPerformed(ActionEvent e) {
boolean flg = ((JCheckBox)e.getSource()).isSelected();
for(JButton b:list) b.setContentAreaFilled(flg);
boolean flg = ((JCheckBox) e.getSource()).isSelected();
for (JButton b: list) {
b.setContentAreaFilled(flg);
}
p.revalidate();
}
}),
new JCheckBox(new AbstractAction("setRolloverEnabled") {
@Override public void actionPerformed(ActionEvent e) {
boolean flg = ((JCheckBox)e.getSource()).isSelected();
for(JButton b:list) b.setRolloverEnabled(flg);
boolean flg = ((JCheckBox) e.getSource()).isSelected();
for (JButton b: list) {
b.setRolloverEnabled(flg);
}
p.revalidate();
}
})
);
View in GitHub: Java, Kotlin解説
上記のサンプルでは、JButton
の状態(例えばフォーカスの有無を描画するか?など)をテストします。これらはLook & Feel
によって効果が異なる場合があるようです。
解説
上記のサンプルでは、フォーカスの有無を表示するかなどの設定を切り替えてJButton
の描画をテストしています。これらはLook & Feel
に依存しそれぞれ有効か無効かなどが異なります。
- setFocusPainted
- setBorderPainted
- setContentAreaFilled
- setRolloverEnabled
- setFocusPainted
- フォーカス状態の描画
- setBorderPainted
- ボーダー(フチの装飾)の描画
- setContentAreaFilled
- ボタンのコンテンツ領域(ボタンのテキストやアイコン以外の領域)の描画
- setRolloverEnabled
- ロールオーバー効果の描画