• 追加された行はこの色です。
  • 削除された行はこの色です。
TITLE:JScrollBarをJScrollPaneの左と上に配置
#navi(../)
*JScrollBarをJScrollPaneの左と上に配置 [#l79e30ba]
>編集者:[[Terai Atsuhiro>terai]]~
作成日:2007-01-08~
更新日:&lastmod;

#contents

**概要 [#o74fb359]
JScrollBarの配置位置を、JScrollPaneの左側、上側に変更します。

#screenshot

**サンプルコード [#c9e13a36]
 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);

-&jnlp;
-&jar;
-&zip;

**解説 [#y5955037]
- 水平スクロールバーを右から左に
-- JScrollPane#setComponentOrientationメソッドで、ComponentOrientation.RIGHT_TO_LEFTを使用しています。

- 垂直スクロールバーを下から上に
-- JScrollPane#getHorizontalScrollBar()メソッドでスクロールバーを取得し、パネルレイアウトを使ってJScrollPaneの上部に配置されているように見せかけています。

**参考リンク [#u3788d1b]
-[[JScrollPane with scroll bar on the left>http://forum.java.sun.com/thread.jspa?threadID=600107]]

**コメント [#ybd1b696]
#comment