Wednesday, May 16, 2012

Try to add a scrollpane to a JTable component

I try to make a scrollbar on my JTable, but it not works. I have a JTable with 21 rows and 5 columns. I have a scrollpane object, and I constructs this like



public Targy_felv() {

JScrollPane scrollPane;
JFrame frame = new JFrame();
frame.setVisible(true);
frame.setSize(600, 300);
table = new JTable();
Object o[] = new Object[]{"Tárgynév", "Oktató", "Kredit", "Félév", "Tárgykód"};
table.setModel(new DefaultTableModel(get_Tárgyak(), o));
scrollPane = new JScrollPane();
scrollPane.getViewport().add(table);
frame.add(table);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}




No comments:

Post a Comment