I've got an app with a GUI that includes a JTable. I'd like for the
table to be scrollable, so I've created a JScrollPane on it. However,
the horizontal scrollbar doesn't have a scroll knob on it, and using the
left/right scroll buttons doesn't cause it to scroll. How can I get the
horizontal scrolling working?
Relevant code fragment below.
-----------------------------------------------
JFrame frame = new JFrame(title);
JDesktopPane JDPane = new JDesktopPane();
frame.getContentPane().add(JDPane);
JInternalFrame JIFrame1 = new JInternalFrame(title + " JIFrame1");
JDPane.add(JIFrame1);
JTable table = new JTable(100,100);
JIFrame1.getContentPane().add(table);
table.setVisible(true);
JScrollPane JSPane = new JScrollPane(table);
JSPane.setPreferredSize(new Dimension(100,100));
JSPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
JSPane.getHorizontalScrollBar().setEnabled(true);
JIFrame1.getContentPane().add(JSPane);
JIFrame1.setClosable(true);
JIFrame1.setResizable(true);
JIFrame1.setSize(200,200);
JIFrame1.setVisible(true);
frame.setSize(800,700);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
Richard F.L.R.Snashall - 11 Apr 2005 11:40 GMT
> I've got an app with a GUI that includes a JTable. I'd like for the
> table to be scrollable, so I've created a JScrollPane on it. However,
[quoted text clipped - 4 lines]
> Relevant code fragment below.
> -----------------------------------------------
> JSPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
This sounds a lot like the symptoms I had once. The only way I
found to fix it was (I accidently found this) to set the layout
to BoxLayout in the outer frame. I do not know if that will
work in your case, though.
Christian Kaufhold - 11 Apr 2005 12:11 GMT
> I've got an app with a GUI that includes a JTable. I'd like for the
> table to be scrollable, so I've created a JScrollPane on it. However,
> the horizontal scrollbar doesn't have a scroll knob on it, and using the
> left/right scroll buttons doesn't cause it to scroll. How can I get the
> horizontal scrolling working?
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
Christian
Kurt Underhay - 11 Apr 2005 12:41 GMT
>>I've got an app with a GUI that includes a JTable. I'd like for the
>>table to be scrollable, so I've created a JScrollPane on it. However,
[quoted text clipped - 5 lines]
>
> Christian
Perfect - works fine now, thanks.