1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| public class Table {
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(200,130);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Object[][] data = new Object[][]{
{1,2,3,4,5},{6,7,8,9,10},{1,2,3,4,5},{6,7,8,9,10},
{1,2,3,4,5},{6,7,8,9,10},{1,2,3,4,5},{6,7,8,9,10}
};
Object[] name = new Object[]{"0","1","2","3","4"};
final JTable table = new JTable(data, name);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
JScrollPane sp = new JScrollPane(table);
frame.getContentPane().add(sp, BorderLayout.CENTER);
JButton button = new JButton("Next");
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
Point p = table.getLocation();
Point newP = new Point(p.x-20,p.y);
table.setLocation(newP);
}
});
frame.getContentPane().add(button, BorderLayout.SOUTH);
frame.setVisible(true);
}
} |
Partager