JTable Pagination

Ads

 
 

Share on Google+Share on Google+

Rajeev
JTable Pagination
0 Answer(s)      2 years and 7 months ago
Posted in : Swing AWT

Hello , I have the following Code. I am able to fetch the Data from the Database. But i need to implement pagination for the same. Can someone please help me out with this ? I have tried out many things from the internet.. but i can't really understand what i should be doing .

CODE :

package javaapplication1;

import com.itextpdf.text.Document; import com.itextpdf.text.DocumentException; import com.itextpdf.text.pdf.PdfContentByte; import com.itextpdf.text.pdf.PdfTemplate; import com.itextpdf.text.pdf.PdfWriter; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Font; import java.awt.Graphics2D; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.table.DefaultTableModel; import javax.swing.JTable; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableColumn; import net.proteanit.sql.DbUtils;

public final class menuframe extends javax.swing.JFrame { static final String JDBC_DRIVER ="com.mysql.jdbc.Driver"; static final String DB_URL="jdbc:mysql://localhost/user"; static final String USER = "root"; static final String PASS="techsoft";

Connection con=null; ResultSet rs=null; PreparedStatement ps =null;

public menuframe() throws SQLException {
            initComponents();                         
                try{
                    Class.forName("com.mysql.jdbc.Driver");
        con = DriverManager.getConnection(DB_URL, USER, PASS);

                }
                catch(ClassNotFoundException | SQLException e){}

          Update_Table();          
}

private void Update_Table() throws SQLException { String sql="SELECT * FROM details"; ps=con.prepareStatement(sql); rs=ps.executeQuery(); table1.setModel(DbUtils.resultSetToTableModel(rs));

}

@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">                          
private void initComponents() {

    jScrollPane3 = new javax.swing.JScrollPane();
    jPanel1 = new javax.swing.JPanel();
    jLabel1 = new javax.swing.JLabel();
    jLabel2 = new javax.swing.JLabel();
    jLabel3 = new javax.swing.JLabel();
    jLabel4 = new javax.swing.JLabel();
    jLabel5 = new javax.swing.JLabel();
    jLabel6 = new javax.swing.JLabel();
    jLabel7 = new javax.swing.JLabel();
    jLabel8 = new javax.swing.JLabel();
    jLabel9 = new javax.swing.JLabel();
    jLabel10 = new javax.swing.JLabel();
    jLabel11 = new javax.swing.JLabel();
    jTextField1 = new javax.swing.JTextField();
    jTextField3 = new javax.swing.JTextField();
    jTextField4 = new javax.swing.JTextField();
    jTextField5 = new javax.swing.JTextField();
    jTextField6 = new javax.swing.JTextField();
    jTextField7 = new javax.swing.JTextField();
    jTextField8 = new javax.swing.JTextField();
    jTextField9 = new javax.swing.JTextField();
    jTextField10 = new javax.swing.JTextField();
    Clear_btn = new javax.swing.JButton();
    Pdf_export = new javax.swing.JButton();
    jTextField2 = new javax.swing.JTextField();
    jScrollBar = new javax.swing.JScrollPane();
    table1 = new javax.swing.JTable()
    {
        public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
            Component comp = super.prepareRenderer(renderer, row, column);
            comp.setBackground(row % 2 == 0 ? Color.white : Color.cyan);

            int rendererWidth = comp.getPreferredSize().width;
            TableColumn tableColumn = getColumnModel().getColumn(column);
            tableColumn.setPreferredWidth(Math.max(rendererWidth +
                getIntercellSpacing().width,
                tableColumn.getPreferredWidth()));

        return comp;
    }
}
;
Add_to_table = new javax.swing.JButton();
Excel_Export = new javax.swing.JButton();
jLabel12 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jSeparator1 = new javax.swing.JPopupMenu.Separator();
jMenuItem2 = new javax.swing.JMenuItem();
jSeparator2 = new javax.swing.JPopupMenu.Separator();
jMenuItem3 = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Main Menu");
setAlwaysOnTop(true);
setFocusTraversalPolicyProvider(true);
setLocationByPlatform(true);
setMaximizedBounds(new java.awt.Rectangle(20, 40, 50, 100));
setMinimumSize(new java.awt.Dimension(500, 500));
setResizable(false);
getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

jScrollPane3.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane3.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
jScrollPane3.setViewportBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
jScrollPane3.setAutoscrolls(true);
jScrollPane3.setMinimumSize(new java.awt.Dimension(1500, 1500));
jScrollPane3.setPreferredSize(new java.awt.Dimension(1370, 768));

jPanel1.setBackground(java.awt.SystemColor.textHighlight);
jPanel1.setBorder(javax.swing.BorderFactory.createMatteBorder(2, 2, 2, 2, new java.awt.Color(0, 0, 0)));
jPanel1.setMinimumSize(new java.awt.Dimension(920, 680));
jPanel1.setOpaque(false);
jPanel1.setPreferredSize(new java.awt.Dimension(1366, 780));
jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

jLabel1.setBackground(new java.awt.Color(255, 255, 255));
jLabel1.setFont(new java.awt.Font("Comic Sans MS", 2, 18)); // NOI18N
jLabel1.setForeground(new java.awt.Color(255, 255, 255));
jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(460, 0, 351, 40));

jLabel2.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.disabledShadow"));
jLabel2.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
jLabel2.setForeground(new java.awt.Color(255, 255, 255));
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel2.setText("First Name");
jLabel2.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.white, new java.awt.Color(255, 255, 255), java.awt.Color.white, java.awt.Color.white));
jLabel2.setOpaque(true);
jLabel2.setPreferredSize(new java.awt.Dimension(85, 30));
jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 50, 150, 40));

jLabel3.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.disabledShadow"));
jLabel3.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
jLabel3.setForeground(new java.awt.Color(255, 255, 255));
jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel3.setText("Last Name");
jLabel3.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white));
jLabel3.setOpaque(true);
jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(720, 50, 150, 40));

jLabel4.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.disabledShadow"));
jLabel4.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
jLabel4.setForeground(new java.awt.Color(255, 255, 255));
jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel4.setIcon(new javax.swing.ImageIcon("C:\\Users\\Rajeev sharma\\Desktop\\circular82.png")); // NOI18N
jLabel4.setText("Age");
jLabel4.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white));
jLabel4.setOpaque(true);
jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 170, 150, 40));

jLabel5.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.disabledShadow"));
jLabel5.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
jLabel5.setForeground(new java.awt.Color(255, 255, 255));
jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel5.setIcon(new javax.swing.ImageIcon("C:\\Users\\Rajeev sharma\\Desktop\\birthday13.png")); // NOI18N
jLabel5.setText("D.O.B");
jLabel5.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white));
jLabel5.setOpaque(true);
jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(720, 110, 150, 40));

jLabel6.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.disabledShadow"));
jLabel6.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
jLabel6.setForeground(new java.awt.Color(255, 255, 255));
jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel6.setIcon(new javax.swing.ImageIcon("C:\\Users\\Rajeev sharma\\Desktop\\woman1.png")); // NOI18N
jLabel6.setText("Gender");
jLabel6.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white));
jLabel6.setOpaque(true);
jPanel1.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 110, 150, 40));

jLabel7.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.disabledShadow"));
jLabel7.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
jLabel7.setForeground(new java.awt.Color(255, 255, 255));
jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel7.setIcon(new javax.swing.ImageIcon("C:\\Users\\Rajeev sharma\\Desktop\\pin66.png")); // NOI18N
jLabel7.setText("Country");
jLabel7.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white));
jLabel7.setOpaque(true);
jPanel1.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(720, 170, 150, 40));

jLabel8.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.disabledShadow"));
jLabel8.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
jLabel8.setForeground(new java.awt.Color(255, 255, 255));
jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel8.setIcon(new javax.swing.ImageIcon("C:\\Users\\Rajeev sharma\\Desktop\\city22.png")); // NOI18N
jLabel8.setText("City");
jLabel8.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white));
jLabel8.setOpaque(true);
jPanel1.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 230, 150, 40));

jLabel9.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.disabledShadow"));
jLabel9.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
jLabel9.setForeground(new java.awt.Color(255, 255, 255));
jLabel9.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel9.setIcon(new javax.swing.ImageIcon("C:\\Users\\Rajeev sharma\\Desktop\\envelope43.png")); // NOI18N
jLabel9.setText("Email");
jLabel9.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white));
jLabel9.setOpaque(true);
jPanel1.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(720, 230, 150, 40));

jLabel10.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.disabledShadow"));
jLabel10.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
jLabel10.setForeground(new java.awt.Color(255, 255, 255));
jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel10.setIcon(new javax.swing.ImageIcon("C:\\Users\\Rajeev sharma\\Desktop\\telephone120.png")); // NOI18N
jLabel10.setText("Ph. No");
jLabel10.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white));
jLabel10.setOpaque(true);
jPanel1.add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(220, 290, 150, 40));

jLabel11.setBackground(javax.swing.UIManager.getDefaults().getColor("Button.disabledShadow"));
jLabel11.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
jLabel11.setForeground(new java.awt.Color(255, 255, 255));
jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel11.setIcon(new javax.swing.ImageIcon("C:\\Users\\Rajeev sharma\\Desktop\\comment13.png")); // NOI18N
jLabel11.setText("Comments");
jLabel11.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white));
jLabel11.setOpaque(true);
jPanel1.add(jLabel11, new org.netbeans.lib.awtextra.AbsoluteConstraints(720, 290, 150, 40));

jTextField1.setFont(new java.awt.Font("Verdana", 0, 14)); // NOI18N
jTextField1.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
jPanel1.add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 50, 166, 40));
jTextField1.getAccessibleContext().setAccessibleName("");

jTextField3.setFont(new java.awt.Font("Verdana", 0, 14)); // NOI18N
jTextField3.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
jPanel1.add(jTextField3, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 170, 166, 40));

jTextField4.setFont(new java.awt.Font("Verdana", 0, 14)); // NOI18N
jTextField4.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
jPanel1.add(jTextField4, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 230, 166, 40));

jTextField5.setFont(new java.awt.Font("Verdana", 0, 14)); // NOI18N
jTextField5.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
jPanel1.add(jTextField5, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 290, 166, 40));

jTextField6.setFont(new java.awt.Font("Verdana", 0, 14)); // NOI18N
jTextField6.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
jPanel1.add(jTextField6, new org.netbeans.lib.awtextra.AbsoluteConstraints(930, 290, 160, 40));

jTextField7.setFont(new java.awt.Font("Verdana", 0, 14)); // NOI18N
jTextField7.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
jPanel1.add(jTextField7, new org.netbeans.lib.awtextra.AbsoluteConstraints(930, 50, 160, 40));

jTextField8.setFont(new java.awt.Font("Verdana", 0, 14)); // NOI18N
jTextField8.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
jPanel1.add(jTextField8, new org.netbeans.lib.awtextra.AbsoluteConstraints(930, 110, 160, 40));

jTextField9.setFont(new java.awt.Font("Verdana", 0, 14)); // NOI18N
jTextField9.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
jPanel1.add(jTextField9, new org.netbeans.lib.awtextra.AbsoluteConstraints(930, 170, 160, 40));

jTextField10.setFont(new java.awt.Font("Verdana", 0, 14)); // NOI18N
jTextField10.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
jPanel1.add(jTextField10, new org.netbeans.lib.awtextra.AbsoluteConstraints(930, 230, 160, 40));

Clear_btn.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
Clear_btn.setText("Clear");
Clear_btn.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
        Clear_btnActionPerformed(evt);
    }
});
jPanel1.add(Clear_btn, new org.netbeans.lib.awtextra.AbsoluteConstraints(670, 370, 120, 40));

Pdf_export.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
Pdf_export.setText("Export to PDF");
Pdf_export.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
        Pdf_exportActionPerformed(evt);
    }
});
jPanel1.add(Pdf_export, new org.netbeans.lib.awtextra.AbsoluteConstraints(650, 660, 150, 40));

jTextField2.setFont(new java.awt.Font("Verdana", 0, 14)); // NOI18N
jTextField2.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
jPanel1.add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(430, 110, 166, 40));

jScrollBar.setViewportBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white, java.awt.Color.white));

table1.setAutoCreateRowSorter(true);
table1.getTableHeader().setFont(new Font("SansSerif",Font.BOLD,12));
table1.getTableHeader().setForeground(Color.blue);
table1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED, new java.awt.Color(0, 0, 0), new java.awt.Color(0, 0, 0), java.awt.Color.black, java.awt.Color.black));
table1.setFont(new java.awt.Font("Comic Sans MS", 1, 12)); // NOI18N
table1.setModel(new javax.swing.table.DefaultTableModel(
    new Object [][] {

    },
    new String [] {
        "First Name", "Last Name", "D.O.B", "Ph.No", "City", "Country", "Email"
    }
));
table1.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
table1.setColumnSelectionAllowed(true);
table1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
table1.setDropMode(javax.swing.DropMode.ON);
table1.setEditingRow(3);
table1.setFillsViewportHeight(true);
table1.setGridColor(new java.awt.Color(255, 0, 0));
table1.setIntercellSpacing(new Dimension()
);
table1.setRowHeight(23);
table1.setRowMargin(5);
table1.getTableHeader().setReorderingAllowed(false);
jScrollBar.setViewportView(table1);
table1.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
if (table1.getColumnModel().getColumnCount() > 0) {
    table1.getColumnModel().getColumn(2).setHeaderValue("D.O.B");
    table1.getColumnModel().getColumn(3).setHeaderValue("Ph.No");
    table1.getColumnModel().getColumn(4).setResizable(false);
    table1.getColumnModel().getColumn(4).setHeaderValue("City");
    table1.getColumnModel().getColumn(5).setHeaderValue("Country");
    table1.getColumnModel().getColumn(6).setHeaderValue("Email");
}

jPanel1.add(jScrollBar, new org.netbeans.lib.awtextra.AbsoluteConstraints(420, 440, 310, 190));

Add_to_table.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
Add_to_table.setText("Add to Table");
Add_to_table.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
        Add_to_tableActionPerformed(evt);
    }
});
jPanel1.add(Add_to_table, new org.netbeans.lib.awtextra.AbsoluteConstraints(480, 370, 140, 40));

Excel_Export.setFont(new java.awt.Font("Comic Sans MS", 1, 14)); // NOI18N
Excel_Export.setText("Export to Excel");
Excel_Export.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEvent evt) {
        Excel_ExportActionPerformed(evt);
    }
});
jPanel1.add(Excel_Export, new org.netbeans.lib.awtextra.AbsoluteConstraints(440, 660, 160, 40));

jLabel12.setFont(new java.awt.Font("Comic Sans MS", 2, 18)); // NOI18N
jLabel12.setIcon(new javax.swing.ImageIcon("C:\\Users\\Rajeev sharma\\Downloads\\night_falling-wallpaper-1920x1080.jpg")); // NOI18N
jLabel12.setText("jLabel12");
jLabel12.setAlignmentY(0.0F);
jLabel12.setMinimumSize(new java.awt.Dimension(400, 600));
jLabel12.setOpaque(true);
jLabel12.setPreferredSize(new java.awt.Dimension(1500, 800));
jPanel1.add(jLabel12, new org.netbeans.lib.awtextra.AbsoluteConstraints(-500, -10, 1880, 900));

jScrollPane3.setViewportView(jPanel1);

getContentPane().add(jScrollPane3, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 1500, 749));

jMenu1.setText("Reports");
jMenu1.setFont(new java.awt.Font("Segoe Print", 2, 18)); // NOI18N

jMenuItem1.setBackground(javax.swing.UIManager.getDefaults().getColor("MenuBar.shadow"));
jMenuItem1.setFont(new java.awt.Font("Comic Sans MS", 2, 16)); // NOI18N
jMenuItem1.setText("Detail Report");
jMenuItem1.setOpaque(true);
jMenuItem1.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mousePressed(java.awt.event.MouseEvent evt) {
        jMenuItem1MousePressed(evt);
    }
});
jMenu1.add(jMenuItem1);
jMenu1.add(jSeparator1);

jMenuItem2.setBackground(javax.swing.UIManager.getDefaults().getColor("MenuBar.shadow"));
jMenuItem2.setFont(new java.awt.Font("Comic Sans MS", 2, 16)); // NOI18N
jMenuItem2.setText("Summary Report");
jMenuItem2.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mousePressed(java.awt.event.MouseEvent evt) {
        jMenuItem2MousePressed(evt);
    }
});
jMenu1.add(jMenuItem2);
jMenu1.add(jSeparator2);

jMenuItem3.setBackground(javax.swing.UIManager.getDefaults().getColor("MenuBar.shadow"));
jMenuItem3.setFont(new java.awt.Font("Comic Sans MS", 2, 16)); // NOI18N
jMenuItem3.setText("Admin Report");
jMenuItem3.addMouseListener(new java.awt.event.MouseAdapter() {
    public void mousePressed(java.awt.event.MouseEvent evt) {
        jMenuItem3MousePressed(evt);
    }
});
jMenu1.add(jMenuItem3);

jMenuBar1.add(jMenu1);

jMenu2.setText("Settings");
jMenu2.setFont(new java.awt.Font("Segoe Print", 2, 18)); // NOI18N
jMenuBar1.add(jMenu2);

setJMenuBar(jMenuBar1);

pack();
setLocationRelativeTo(null);
}// </editor-fold>                        

private void jMenuItem1MousePressed(java.awt.event.MouseEvent evt) {                                        
    jLabel1.setText("WELCOME TO DETAIL REPORT");

}                                       

private void Clear_btnActionPerformed(java.awt.event.ActionEvent evt) {                                          
    jTextField1.setText("");
     jTextField2.setText("");
    jTextField3.setText("");
            jTextField4.setText("");
             jTextField5.setText("");
               jTextField6.setText("");
                 jTextField7.setText("");
                   jTextField8.setText("");
                     jTextField9.setText("");
                       jTextField10.setText("");

}                                         

private void jMenuItem3MousePressed(java.awt.event.MouseEvent evt) {                                        
    jLabel1.setText("WELCOME TO ADMIN REPORT");
}                                       

private void jMenuItem2MousePressed(java.awt.event.MouseEvent evt) {                                        
    jLabel1.setText("WELCOME TO SUMMARY REPORT");
}                                       

private void Add_to_tableActionPerformed(java.awt.event.ActionEvent evt) {

DefaultTableModel model=(DefaultTableModel) table1.getModel(); model.addRow(new Object[]{ jTextField1.getText(),jTextField7.getText(),jTextField8.getText(),jTextField5.getText(),jTextField4.getText(), jTextField9.getText(),jTextField10.getText() }); }

private void Excel_ExportActionPerformed(java.awt.event.ActionEvent evt) {                                             
 ExcelExport exp=new ExcelExport();

 exp.toExcel(table1, new File("E:\\Rajeev Sharma\\export.xls"));
   System.out.println("exporting!");  

}                                            


void print()
{
    Document doc=new Document();
    try{
        PdfWriter writer;

       writer = PdfWriter.getInstance(doc, new FileOutputStream("E:\\Rajeev Sharma\\export.pdf"));
        doc.open();

        PdfContentByte cb = writer.getDirectContent();
                table1.updateUI();
        PdfTemplate tp=cb.createTemplate(800,800);

        Graphics2D g2 = tp.createGraphicsShapes(800,800);

          table1.print(g2);
          g2.dispose();
          cb.addTemplate(tp,30,00);

    }catch(DocumentException | FileNotFoundException e){}
    doc.close();
}
private void Pdf_exportActionPerformed(java.awt.event.ActionEvent evt) {                                           
        print();
}                                          


public static void main(String args[]) {
                        java.awt.EventQueue.invokeLater(new Runnable() {   
        @Override
                  public void run() {
            try {
                new menuframe().setVisible(true);
            } catch (SQLException ex) {
                Logger.getLogger(menuframe.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
    });

      }


// Variables declaration - do not modify                     
private javax.swing.JButton Add_to_table;
private javax.swing.JButton Clear_btn;
private javax.swing.JButton Excel_Export;
private javax.swing.JButton Pdf_export;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel12;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollBar;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JPopupMenu.Separator jSeparator1;
private javax.swing.JPopupMenu.Separator jSeparator2;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField10;
private javax.swing.JTextField jTextField2;
private javax.swing.JTextField jTextField3;
private javax.swing.JTextField jTextField4;
private javax.swing.JTextField jTextField5;
private javax.swing.JTextField jTextField6;
private javax.swing.JTextField jTextField7;
private javax.swing.JTextField jTextField8;
private javax.swing.JTextField jTextField9;
private javax.swing.JTable table1;
// End of variables declaration                   

private Object GetData(JTable table1, int i, int i0) {
    throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

}

Ads
View Answers
Ads









Related Tutorials/Questions & Answers:
JTable Pagination
JTable Pagination  Hello , I have the following Code. I am able to fetch the Data from the Database. But i need to implement pagination for the same. Can someone please help me out with this ? I have tried out many things from
Pagination
Pagination  How to create pagination in jsp with EJB using MS SQL
Advertisements
pagination
pagination  How to set pagination using java script to display data
Pagination
Pagination  How to implement pagination in struts using hibernate
Pagination
Pagination  How to apply pagination in JSP. Please help
pagination
pagination   Simple way for pagination in jsp using java script to display data without send database
Pagination
Pagination  Is their plug n play approach for creating pagination? 1) Server side as well as client side
Pagination
Pagination  I want to write one where condition in sql query in pagination concept
Pagination
Pagination  I want to know how to use pagination in jsp. I have a list object from that i want to display 3 questions per page can u help me
pagination
pagination  I need to give pagination with where condition (query="select * from qtn where qid='"+replyQuesionId+"'limit "+iPageNo+","+showRows+"" ) like this I want, without where condition it is working but with condition
pagination
pagination  I need to give pagination with where condition (query.......   Here is a simple jsp pagination code where we have used mysql database...()) { totalRows=rs2.getInt("cnt"); } %> <html> <h3>Pagination of JSP
Pagination
=rs2.getInt("cnt"); } %> Pagination of JSP page Terr_Code Terr_Name
pagination
pagination  how can i start pagination in jsp?   Hi Friend, Try the following code: <%@ page language="java" %> <%@ page import...;Pagination of JSP page</h3> <body> <form> <input type="hidden
Pagination
Pagination  pagination in jsp   Hi Friend, Try the following code: <%@ page language="java" %> <%@ page import="java.sql.*" %>...()) { totalRows=rs2.getInt("cnt"); } %> <html> <h3>Pagination of JSP
pagination
code of pagination. In the given code,we have taken the database table student...;Pagination of JSP page</h3> <body> <form> <input type="hidden
JTable
JTable  Values to be displayed in JTextfield when Clicked on JTable Cells
JTable
JTable  i want to delete record from JTable using a MenuItem DELETE. and values of JTable are fetched from database....please reply soon
JTable
JTable   how to select a definite cell which containing a similar text containg to the one which the user entering from a jtable at runtime in java
JTable
JTable  need to add values to a JTable having 4 coloumns ,2 of them are comboboxes
JTable
JTable  Hello, i cannot display data from my table in the database to the cells of my JTable. please help me
jtable
jtable  how to get the values from database into jtable and also add a checkbox into it and then when selected the checkbox it should again insert into database the selected chewckbox.plzz help
jtable
jtable  hi Sir i am working netbeans IDE,I have a jtable when i insert values in jtable then i am unable to print all inserted values,For eg if i insert 1,2,3,4,5,6,7,8 values then , i am getting output
jtable
jtable  hey i have build a form and i m also able to add data from database to jtable along with checkbox.the only problem is that if i select multiple checkboxes the data doesnt get inserted into new database and if only one
JTable
JTable  Hi I have problems in setting values to a cell in Jtable which is in a jFrame which implements TableModelListener which has a abstract method tableChanged(TableModelEvent e) . I'll be loading values from data base when
JTable
"}; JTable table=new JTable(data,labels); JScrollPane pane=new JScrollPane
Pagination in java
Pagination in java  How to handle pagination when there are records like say in millions in java? Or do we handle this using SQL? I as asked... far good performance then Java pagination. Thanks
pagination in jsf
pagination in jsf  Hi , i am implemeting an online exam system , i have placed my questions as an arraylist in my jsp file within tag , but now i want to paginate these questions based on respective questions by clicking
jsp pagination
jsp pagination  I want to implement pagination on jsp page Each jsp page having some radio buttons, on click of next previous page selected radio buttons are reset. I want to maintain state of selected radio buttons on previous