所以我创建了一些演示代码,见下文。
我所看到的是,如果JScrollPane位于JInternalFrame中,并且组件方向设置为从右向左,则在缩小框架时,滚动条将保留在内容的左侧。我希望,作为RtL,它将保留在内容的右侧,如果滚动窗格未添加到内部框架,则为真(参见两个框架 - 一个在演示中显示在另一个框架后面)。
这是一个Java错误还是我忘了做某事?
以下是演示代码:
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
public class JScrollBarTest
{
public static void main(String[] a)
{
try
{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch (Exception e) { }
runInternalFrameDemo();
runNormalDemo();
}
private static void runInternalFrameDemo()
{
// Frame...
final JFrame frame = new JFrame("Internal Frame Demo");
frame.setSize(new Dimension(500, 500));
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
// Desktop pane...
JDesktopPane desktopPane = new JDesktopPane();
// Table...
JTable table = getTable();
// Scroll pane...
JScrollPane scrollPane = new JScrollPane();
// Internal frame...
final JInternalFrame internalFrame = new JInternalFrame("Test Internal Frame", true, true, true, true);
internalFrame.setSize(400, 300);
internalFrame.setLocation(50, 50);
internalFrame.setVisible(true);
// Add everything...
frame.setContentPane(desktopPane);
desktopPane.add(internalFrame);
internalFrame.setContentPane(scrollPane);
scrollPane.setViewportView(table);
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
internalFrame.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
frame.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
frame.setVisible(true);
}
});
}
private static void runNormalDemo()
{
// Frame...
final JFrame frame = new JFrame("Normal Demo");
frame.setSize(new Dimension(500, 500));
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
// Table...
JTable table = getTable();
// Scroll pane...
JScrollPane scrollPane = new JScrollPane();
// Add everything...
frame.setContentPane(scrollPane);
scrollPane.setViewportView(table);
SwingUtilities.invokeLater(new Runnable()
{
public void run()
{
frame.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
frame.setVisible(true);
}
});
}
private static JTable getTable()
{
final String[] columns = { "test 1", "test 2", "test 3", "test 4" };
final Object[][] data = { { "1", "2", "3", "4" }, { "1", "2", "3", "4" } };
final JTable table = new JTable(data, columns);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
return table;
}
}
提前致谢。
编辑:
对于缺乏清晰度的道歉 - 写得非常匆忙。
问题在于,当我减少表的 width 时,'Normal Demo'(不包含在JInternalFrame中)水平滚动条从右边开始,在那里做同样的对于“内部框架演示”,水平滚动条从左侧开始。
有什么想法吗?
答案 0 :(得分:1)
正如所讨论的,使用Java 1.6,内部和标准帧的行为似乎没有区别。
错误“JScrollPane ignores ComponentOrientation”描述了您的问题,但很久以前就修好了。
错误“JScrollPane does not layout properly with RTL (RIGHT_TO_LEFT)”仍处于打开状态,可能会导致您的问题。
我在Sun Forums找到了一个解决方案,它让它对我有用,虽然问题略有不同。垂直滚动条显示在右侧而不是左侧。
scrollPane.setLayout(new ScrollPaneLayout() {
@Override
public void layoutContainer(Container parent) {
JScrollPane scrollPane = (JScrollPane) parent;
scrollPane.setComponentOrientation(
ComponentOrientation.LEFT_TO_RIGHT);
super.layoutContainer(parent);
scrollPane.setComponentOrientation(
ComponentOrientation.RIGHT_TO_LEFT);
}
});
当前的行为对我来说听起来像个错误,因为bug(见上文)已得到修复。
答案 1 :(得分:0)
我不确定你看到了什么,但这就是我所看到的。
alt text http://dl.dropbox.com/u/3608004/jframe.png
在这两种情况下,滚动条都在左侧(最小化之前和之后),这是正确的。在阿拉伯语(从右到左的语言)中,滚动条的默认位置在左侧