Swing/InternalFrameLayoutTitlePaneAtOrigin のバックアップ(No.2)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- Swing/InternalFrameLayoutTitlePaneAtOrigin へ行く。
- category: swing folder: InternalFrameLayoutTitlePaneAtOrigin title: JInternalFrameのタイトルパネルをフレーム原点から描画する tags: [JInternalFrame, LookAndFeel, UIManager] author: aterai pubdate: 2022-10-24T03:44:45+09:00 description: JInternalFrameのタイトルパネルをフレーム原点から描画するかBorderを考慮した配置にするかを切り替えます。 image: https://drive.google.com/uc?id=1_RXTVB4CXv1uNAlIn03U3C2adWtAa1w1
概要
JInternalFrameのタイトルパネルをフレーム原点から描画するかBorderを考慮した配置にするかを切り替えます。
Screenshot

Advertisement
サンプルコード
String key = "InternalFrame.layoutTitlePaneAtOrigin";
JDesktopPane desktop = new JDesktopPane();
boolean b = UIManager.getBoolean(key);
JCheckBox check = new JCheckBox("InternalFrame TitlePane layout", b) {
@Override public void updateUI() {
super.updateUI();
boolean b = UIManager.getLookAndFeelDefaults().getBoolean(key);
setSelected(b);
UIManager.put(key, b);
SwingUtilities.updateComponentTreeUI(desktop);
}
};
check.addActionListener(e -> {
UIManager.put(key, ((JCheckBox) e.getSource()).isSelected());
SwingUtilities.updateComponentTreeUI(desktop);
});
check.setOpaque(false);
addFrame(desktop, 0, true);
addFrame(desktop, 1, false);
View in GitHub: Java, Kotlin解説
BasicLookAndFeel、MetalLookAndFeel、MotifLookAndFeel、NimbusLookAndFeelのデフォルトはfalseMetalLookAndFeelでこの設定をtrueにするとタイトルパネルがJInternalFrameのBorderを考慮せずに原点から幅全体が描画されて不自然なレイアウトのタイトルパネルになってしまうMotifLookAndFeelでこの設定をtrueにするとタイトルパネルがJInternalFrameのBorderを考慮せずに原点から幅全体を占めるようレイアウトされるNimbusLookAndFeelでこの設定をtrueにするとフレーム化されている場合は変化なしだが、アイコン化されている場合はその高さが変化する場合がある
WindowsLookAndFeel、GTKLookAndFeelのデフォルトはtrueWindowsLookAndFeelでこの設定をfalseにするとタイトルパネルがJInternalFrameのBorderを考慮して縮小して描画されて不自然なレイアウトのタイトルパネルになってしまうGTKLookAndFeelでこの設定をfalseにするとタイトルパネルアイコンがタイトル文字列にかぶったり最大化、最小化、閉じるボタンがJInternalFrameの内側に移動して不自然なレイアウトのタイトルパネルになってしまう
参考リンク
- BasicInternalFrameUI#getNorthPane() (Java Platform SE 8)
InternalFrame.layoutTitlePaneAtOriginの設定は通常は変更する必要はなく、タイトルパネル(NorthPane)を自作する必要がある場合のみ考慮すればよさそう?