Can't scroll horizontal scrollbar

K

Kurt Underhay

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);
 
C

castillo.bryan

Check out the method setAutoResizeMode on JTable. I believe that the
default behavior of a JTable is to resize itself to the viewable area.
If you set it to AUTO_RESIZE_OFF, you will probably see the scroll bar.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top