So I have created some demo code, see below.
What I am seeing is that if a JScrollPane is within a JInternalFrame and component orientation is set to right-to-left, when minmising the frame, the scroll bar stays to the left of the content. I would expect, seeing as RtL, that it would stay to the right of the content, which is true if the scroll pane is not added to an internal frame (see both frames - one appears behind the other in the demo).
So is this a Java bug or have I forgotten to do something?
Here's the demo code:
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;
}
}
Thanks in advance.
EDIT:
Apologies for the lack of clarity - written in quite a rush.
The issue is that when I reduce the width of the table, the 'Normal Demo' (not contained within a JInternalFrame) the horizontal scroll bar starts on the right, where as, doing the same for the 'Internal Frame Demo', the horizontal scroll bar starts on the left.
Any ideas?