paging in java swing with jtable and database

不想你离开。 提交于 2020-07-31 04:17:48

问题


I am new to java and I am working on Jtable with database.i fill up my jtable by data from database ,now I need to use paging and I don't know how to implement this in my code,i used DbUtils to fill up the jtable,every think is ok but the problem is that i don't know how to use pagination, thank you in advance for any sharing of information and help

public class FenetrePers extends JFrame  {
    private JTextField rechNomField;
    private JTextField rechPrenField;
    private JTextField rechemailField;
    private JTextField rechtelephField;
    private JButton btnNewButton_2;
    AjoutPers ajpers;
    
    
    Connection cnx =null;
    PreparedStatement prepared=null;
    ResultSet resultat=null;
    private JScrollPane scrollPane;
    private JTable table;
    private JButton editButton;
    private JButton deleteButton;
    
    public FenetrePers() {
        cnx=ConnectionSql.ConnexionDB();
        
        this.setExtendedState(this.MAXIMIZED_BOTH);
        
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(null);
        
        
        
        JLabel lblNewLabel = new JLabel("       Gestion du personnel");
        lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 14));
        lblNewLabel.setForeground(Color.BLACK);
        lblNewLabel.setBounds(10, 23, 181, 21);
        getContentPane().add(lblNewLabel);
        
        rechNomField = new JTextField();
        rechNomField.setBounds(27, 84, 175, 32);
        getContentPane().add(rechNomField);
        rechNomField.setColumns(10);
        
        rechPrenField = new JTextField();
        rechPrenField.setBounds(298, 84, 163, 32);
        getContentPane().add(rechPrenField);
        rechPrenField.setColumns(10);
        
        rechemailField = new JTextField();
        rechemailField.setBounds(587, 84, 163, 32);
        getContentPane().add(rechemailField);
        rechemailField.setColumns(10);
        
        rechtelephField = new JTextField();
        rechtelephField.setBounds(844, 84, 157, 32);
        getContentPane().add(rechtelephField);
        rechtelephField.setColumns(10);
        
        JButton FindButton = new JButton("find");
        FindButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                
                try {
                    UpdateTableSearch();
                } catch (SQLException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                
            }
        });
        FindButton.setBounds(1034, 89, 66, 27);
        getContentPane().add(FindButton);
        
        JButton btnNewButton_1 = new JButton("reset");
        btnNewButton_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                
                String nomS=rechNomField.getText().toString();  
                String prenomS=rechPrenField.getText().toString();  
                String emailS=rechemailField.getText().toString();  
                String telephS=rechtelephField.getText().toString();
                if(!nomS.equals("")|| !prenomS.equals("")|| !emailS.equals("")||!telephS.equals("")) {
                rechNomField.setText("");
                rechPrenField.setText("");
                rechemailField.setText("");
                rechtelephField.setText("");
                UpdateTable();
                
                
            }}
        });
        btnNewButton_1.setBounds(1110, 89, 66, 27);
        getContentPane().add(btnNewButton_1);
        
        btnNewButton_2 = new JButton("Ajouter personnel");
        btnNewButton_2.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                
             ajpers =   new AjoutPers(FenetrePers.this);
            UpdateTable();
            
            }
        });
        btnNewButton_2.setBounds(1034, 24, 142, 32);
        getContentPane().add(btnNewButton_2);
        
        scrollPane = new JScrollPane();
        scrollPane.setBounds(27, 150, 985, 308);
        getContentPane().add(scrollPane);
        
        table = new JTable();
        table.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                
            
            }
        });
        scrollPane.setViewportView(table);

来源:https://stackoverflow.com/questions/63033496/paging-in-java-swing-with-jtable-and-database

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!