Swing/SpinnerButtonLayout のバックアップ(No.12)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- Swing/SpinnerButtonLayout へ行く。
- 1 (2012-08-13 (月) 00:50:40)
- 2 (2012-12-23 (日) 05:32:32)
- 3 (2014-09-30 (火) 00:43:45)
- 4 (2015-02-13 (金) 23:01:45)
- 5 (2016-12-09 (金) 16:33:53)
- 6 (2017-12-03 (日) 00:07:47)
- 7 (2019-08-02 (金) 21:00:48)
- 8 (2021-03-31 (水) 02:33:21)
- 9 (2025-01-03 (金) 08:57:02)
- 10 (2025-01-03 (金) 09:01:23)
- 11 (2025-01-03 (金) 09:02:38)
- 12 (2025-01-03 (金) 09:03:21)
- 13 (2025-01-03 (金) 09:04:02)
- category: swing folder: SpinnerButtonLayout title: JSpinnerのボタンを左右に配置する tags: [JSpinner, ArrowButton, LayoutManager] author: aterai pubdate: 2011-01-24T14:15:43+09:00 description: JSpinnerのレイアウトを変更して、矢印ボタンを左右に配置します。 image:
Summary
JSpinner
のレイアウトを変更して、矢印ボタンを左右に配置します。
Screenshot
Advertisement
Source Code Examples
class SpinnerLayout extends BorderLayout {
@Override public void addLayoutComponent(Component comp, Object constraints) {
Object cons = constraints;
if ("Editor".equals(constraints)) {
cons = "Center";
} else if ("Next".equals(constraints)) {
cons = "East";
} else if ("Previous".equals(constraints)) {
cons = "West";
}
super.addLayoutComponent(comp, cons);
}
}
View in GitHub: Java, KotlinExplanation
Default
- デフォルト
- 右端に増加ボタン、減少ボタンを配置
RIGHT_TO_LEFT
JSpinner#setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT)
で各ボタンを左側に配置
L(Prev), R(Next): 1
BorderLayout#addLayoutComponent(...)
をオーバーライドしてEditor
をCenter
、Next
をEast
、Prev
をWest
に配置するレイアウトマネージャーを作成JSpinner spinner = new JSpinner(model) { @Override public void updateUI() { super.updateUI(); setUI(new BasicSpinnerUI() { @Override protected LayoutManager createLayout() { return new SpinnerLayout(); } }); } };
L(Prev), R(Next): 2
L(Prev), R(Next): 1
と同じレイアウトマネージャーをJSpinner#setLayout(...)
メソッドをオーバーライドして設定JSpinner spinner = new JSpinner(model) { @Override public void setLayout(LayoutManager mgr) { super.setLayout(new SpinnerLayout()); } };