stsanz
asked on
JTable/JScrollPane horizontal scrolling problem
Hi,
In a JApplet, I have a JTable embedded into a JScrollPane and I want to be able to scroll the table horizontally and vertically. The vertical scrolling works perfectly well, but I can't get the horizontal scrolling to work. The horizontal scrollbar appears but has no index, altough the columns spread past the rightmost limit of the scrollpane. Any ideas?
Here is my JTable/JScrollPane creation code (the table model is very simple and contains 12 text columns) :
getContentPane().setLayout (null) ;
m_table = new JTable(m_model) ;
for (int iCol = 0 ; iCol < m_model.getColumnCount() ; iCol++)
m_table.getColumnModel().g etColumn(i Col).setMi nWidth(200 ) ;
JScrollPane scrollPane = new JScrollPane(
m_table,
JScrollPane.VERTICAL_SCROL LBAR_ALWAY S,
JScrollPane.HORIZONTAL_SCR OLLBAR_ALW AYS);
m_table.setPreferredScroll ableViewpo rtSize(new Dimension(1600, 700)) ;
scrollPane.setBounds(0,0,1 150,498) ;
getContentPane().add(scrol lPane) ;
In a JApplet, I have a JTable embedded into a JScrollPane and I want to be able to scroll the table horizontally and vertically. The vertical scrolling works perfectly well, but I can't get the horizontal scrolling to work. The horizontal scrollbar appears but has no index, altough the columns spread past the rightmost limit of the scrollpane. Any ideas?
Here is my JTable/JScrollPane creation code (the table model is very simple and contains 12 text columns) :
getContentPane().setLayout
m_table = new JTable(m_model) ;
for (int iCol = 0 ; iCol < m_model.getColumnCount() ; iCol++)
m_table.getColumnModel().g
JScrollPane scrollPane = new JScrollPane(
m_table,
JScrollPane.VERTICAL_SCROL
JScrollPane.HORIZONTAL_SCR
m_table.setPreferredScroll
scrollPane.setBounds(0,0,1
getContentPane().add(scrol
This works fine:
getContentPane().setLayout (new BorderLayout());
getContentPane().add(scrol lPane,Bord erLayout.C ENTER) ;
getContentPane().setLayout
getContentPane().add(scrol
Of course, if you're adding to a JFrame, the above code is redundant, but as I mentioned earlier, the problem is likely caused by your removing the layout manager.
I've checked it. RootLayout is good enough. CEHJ is right.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
Unless you have a very good reason, calculating your own layouts is not a good idea. Try running your code on another OS and you'll see what I mean.
>>getContentPane().setLayo