
hi i get into a problem of scrolling jtable in scrollpane.Only horizontal scroll is working, vertical scroll is not working...here is m code: try {
PreparedStatement pst=c1.prepareStatement("select * from entry where visit_to_person=?");
pst.setString(1,visit_combo.getSelectedItem().toString());
ResultSet rs =pst.executeQuery();
while(rs.next())
{
vno= rs.getString(1);
vnam=rs.getString(2);
vtp=rs.getString(3);
pur=rs.getString(4);
in=rs.getString(5);
dat=rs.getString(6);
String s[]={vno,vnam,vtp,pur,in,dat};
Vector coldata=new Vector(Arrays.asList(s));
rowdata.add(coldata);
}
String[] head={"VISITOR NO","VISITOR NAME","VISIT TO PERSON","PURPOSE","IN TIME","DATE"};
colname=new Vector(Arrays.asList(head));
tableModel =new DefaultTableModel(rowdata, colname);
table = new JTable(tableModel);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
JTableHeader header = table.getTableHeader();
JScrollPane pane = new JScrollPane(table);
pane.setAutoscrolls(true);
pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
pane.setSize(450,300);
pane.setVisible(true);
panel.add(pane,BorderLayout.CENTER);
JFrame.setDefaultLookAndFeelDecorated(true);
}
catch(SQLException sq){}

import java.sql.*;
import java.util.*;
import javax.swing.*;
class JTableExample extends JFrame {
private static int offset = 50;
public JTableExample(int horizPolicy, int vertPolicy, String title) {
final Vector columnNames = new Vector();
final Vector data = new Vector();
JPanel panel=new JPanel();
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
Statement st = con.createStatement();
ResultSet rs= st.executeQuery("Select * from employee");
ResultSetMetaData md = rs.getMetaData();
int columns = md.getColumnCount();
for (int i = 1; i <= columns; i++){
columnNames.addElement(md.getColumnName(i));
}
while(rs.next()){
Vector row = new Vector(columns);
for (int i = 1; i <= columns; i++){
row.addElement(rs.getObject(i));
}
data.addElement(row);
}
}
catch(Exception e){}
JTable table = new JTable(data, columnNames);
setTitle(title);
offset += 50;
setLocation(offset,offset);
setSize(300,150);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
JScrollPane scroll = new JScrollPane(table);
scroll.setHorizontalScrollBarPolicy(horizPolicy);
scroll.setVerticalScrollBarPolicy(vertPolicy);
getContentPane().add(scroll);
}
public static void main(String[] args) {
JTableExample f=new JTableExample(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED,JScrollPane.
VERTICAL_SCROLLBAR_AS_NEEDED,"HORIZONTAL_SCROLLBAR_AS_NEEDED");
f.setVisible(true);
}
}

really thanku sir for ur early reply...but still have the problem
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.