JTabbedPaneのタブ・ランの回転を無効にする
Total: 2411, Today: 1, Yesterday: 2
Posted by aterai at
Last-modified:
Summary
JTabbedPaneで複数のランにタブをラップする場合でもタブ選択によるランの回転を無効にします。
Screenshot

Advertisement
Source Code Examples
UIManager.put("TabbedPane.tabRunOverlay", 0);
UIManager.put("TabbedPane.selectedLabelShift", 0);
UIManager.put("TabbedPane.labelShift", 0);
UIManager.put("TabbedPane.selectedTabPadInsets", new Insets(0, 0, 0, 0));
JTabbedPane tabbedPane = new JTabbedPane() {
@Override public void updateUI() {
super.updateUI();
setUI(new WindowsTabbedPaneUI() {
@Override protected boolean shouldRotateTabRuns(int tabPlacement) {
return false;
}
});
}
};
View in GitHub: Java, KotlinDescription
- 上:
DefaultMetalLookAndFeel以外のLookAndFeelではJTabbedPaneレイアウトがWRAP_TAB_LAYOUTで複数のランにタブをラップするレイアウトモードの場合、選択されたタブがタブコンテンツに接地するようランの回転が発生するMetalLookAndFeelの場合、MetalTabbedPaneUI.TabbedPaneLayout#rotateTabRuns(int tabPlacement, int selectedRun)メソッドがオーバーライドされて空(なにも実行しない)になっているため、タブ・ランの回転は発生しないMetalTabbedPaneUI#shouldRotateTabRuns(int tabPlacement, int selectedRun)が常にfalseを返すよう設定されているが引数が2つあるこのメソッドは他では全く使用されておらず、BasicTabbedPaneUI#shouldRotateTabRuns(int tabPlacement)メソッドがオーバーライドされていないので無意味- 少なくとも
Java 5以前から存在するコピペミスのバグ?かも(@Overrideが使用可能なら発覚していたはず)
- 少なくとも
- 下:
Override BasicTabbedPaneUI#shouldRotateTabRuns(...)BasicTabbedPaneUI#shouldRotateTabRuns(int tabPlacement)メソッドをオーバーライドして常にfalseを返すよう設定してタブ・ランの回転を無効化UIManager.put("TabbedPane.tabRunOverlay", 0);を設定してタブ・ランの重なりを除去UIManager.put("TabbedPane.labelShift", 0);とUIManager.put("TabbedPane.selectedLabelShift", 0);を設定してタブテキストのシフトを無効化UIManager.put("TabbedPane.selectedTabPadInsets", new Insets(0, 0, 0, 0));を設定して選択タブのサイズ拡張を無効化
Reference
- BasicTabbedPaneUI#shouldRotateTabRuns(int) (Java Platform SE 8)
- JTabbedPaneのタブのテキストシフト量を変更する
- [JDK-6855659] Ability to disable tab run rotation - Java Bug System