Swing/LeftScrollBar のバックアップ(No.18)
- バックアップ一覧
- 差分 を表示
- 現在との差分 を表示
- 現在との差分 - Visual を表示
- ソース を表示
- Swing/LeftScrollBar へ行く。
- 1 (2007-01-08 (月) 14:26:45)
- 2 (2007-09-13 (木) 18:33:34)
- 3 (2008-03-27 (木) 01:11:39)
- 4 (2008-12-26 (金) 13:52:59)
- 5 (2011-12-15 (木) 03:05:18)
- 6 (2013-02-10 (日) 00:03:12)
- 7 (2013-08-31 (土) 01:40:17)
- 8 (2014-11-25 (火) 03:03:31)
- 9 (2015-10-28 (水) 20:58:47)
- 10 (2017-04-21 (金) 13:22:26)
- 11 (2018-04-10 (火) 17:09:15)
- 12 (2020-04-08 (水) 16:00:07)
- 13 (2021-10-13 (水) 02:44:07)
- 14 (2025-01-03 (金) 08:57:02)
- 15 (2025-01-03 (金) 09:01:23)
- 16 (2025-01-03 (金) 09:02:38)
- 17 (2025-01-03 (金) 09:03:21)
- 18 (2025-01-03 (金) 09:04:02)
- category: swing
folder: LeftScrollBar
title: JScrollBarをJScrollPaneの左と上に配置
tags: [JScrollBar, JScrollPane, BorderLayout]
author: aterai
pubdate: 2007-01-08T14:26:45+09:00
description: JScrollBarの配置位置を、JScrollPaneの左側、上側に変更します。
image:
Summary
JScrollBar
の配置位置を、JScrollPane
の左側、上側に変更します。
Screenshot

Advertisement
Source Code Examples
scroll.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
JPanel panel = new JPanel(new BorderLayout());
int w = scroll.getVerticalScrollBar().getPreferredSize().width;
panel.add(Box.createHorizontalStrut(w), BorderLayout.WEST);
panel.add(scroll.getHorizontalScrollBar(), BorderLayout.CENTER);
add(panel, BorderLayout.NORTH);
add(scroll, BorderLayout.CENTER);
View in GitHub: Java, KotlinExplanation
- 水平スクロールバーを右から左に移動
- パネルのレイアウトに
BorderLayout
を設定してJScrollPane
をそのパネルの中央(BorderLayout.CENTER
)に追加 JScrollPane#setComponentOrientation(...)
メソッドでComponentOrientation.RIGHT_TO_LEFT
を設定
- パネルのレイアウトに
- 垂直スクロールバーを下から上に移動
JScrollPane#getHorizontalScrollBar()
メソッドでスクロールバーを取得し、パネルレイアウトを使ってJScrollPane
の上部(BorderLayout.NORTH
)に配置されているように表示- 左上隅の余白は
Box.createHorizontalStrut(縦スクロールバーの幅)
で埋める