2013-01-18 81 views
0

我有一個包含用阿拉伯語寫的項目的jlist,不幸的是,如果任何項目很長,加載後所有項目都會消失,因爲滾動條不會自動滾動到右側,我應該手動將列表從Horizo​​ntaly滾動到右側。JList水平自動滾動到右邊

我已經將JList的componentOrientation設置爲正確。

有什麼想法?

+2

我建議你創建一個最小的工作例子,張貼在這裏。 –

回答

1

假設JList的是在JScrollPane中,你可以設置水平滾動條的值:

final int maximum = scrollPane.getHorizontalScrollBar().getMaximum(); 
scrollPane.getHorizontalScrollBar().setValue(maximum); 

也喜歡在這裏的例子:

final JFrame frame = new JFrame("JList horizontal auto-scroll to right"); 
frame.setBounds(100, 100, 80, 600); 
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); 
final String[] model = {"aaa", "bbbb", "ccccccccccccccccccccccccc"}; 
final JList<String> jList = new JList<String>(model); 
jList.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT); 
final JScrollPane scrollPane = new JScrollPane(jList); 
frame.getContentPane().add(scrollPane); 
final int maximum = scrollPane.getHorizontalScrollBar().getMaximum(); 
scrollPane.getHorizontalScrollBar().setValue(maximum); 
frame.setVisible(true); 

對於我來說,窗口的樣子這個:

screenshot frame

+0

是的,JList位於JScrollPane中。甚至我添加了'setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);'jlist不會自動滾動到正確的位置。 – Adil

+0

是的,這很奇怪。也許是因爲JScrollPane沒有檢查JList的組件方向?您的應用程序可能以編程方式滾動嗎? –

+0

我認爲'setComponentOrientation'與Scroller無關,因爲它的主要作用是從右向左設置文本方向。關於你最後一個QT,這是我正在尋找的,滾動程序向右。 – Adil