Advertisement
stevennathaniel

Class AbstractTableModel Yang Berhasil Hingga Akhir

Oct 20th, 2015
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.07 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package latihan29;
  7.  
  8.  
  9. import javax.swing.DefaultCellEditor;
  10.  
  11. import javax.swing.JComboBox;
  12.  
  13. import javax.swing.JFrame;
  14.  
  15. import javax.swing.JPanel;
  16.  
  17. import javax.swing.JScrollPane;
  18.  
  19. import javax.swing.JTable;
  20.  
  21. import javax.swing.table.AbstractTableModel;
  22.  
  23. import javax.swing.table.DefaultTableCellRenderer;
  24.  
  25. import javax.swing.table.TableCellRenderer;
  26.  
  27. import javax.swing.table.TableColumn;
  28.  
  29. import java.awt.Component;
  30.  
  31. import java.awt.Dimension;
  32.  
  33. import java.awt.GridLayout;
  34.  
  35. /**
  36.  *
  37.  * @author steven
  38.  */
  39. public class Tabel1 extends javax.swing.JFrame {
  40.  
  41.     /**
  42.      * Creates new form Tabel1
  43.      */
  44.    
  45.    
  46.     /**
  47.      * Menciptakan tabel model
  48.      *
  49.      */
  50.    
  51.    
  52.     class TabelPegawaiModel extends AbstractTableModel{
  53.        
  54.        
  55.         // super("Tabel Pegawai");
  56.        
  57.         String[] namaKolom = {"Nama Pegawai","CheckList"};
  58.        
  59.        
  60.         Object[][] data = {
  61.            
  62.            
  63.             {"Steven Nathaniel", new Boolean(true)},
  64.            
  65.             {"Bill Gates", new Boolean(true)}
  66.            
  67.            
  68.         };
  69.        
  70.        
  71.         // @Override
  72.        
  73.         public int getColumnCount(){
  74.            
  75.             return namaKolom.length;
  76.        
  77.        
  78.     }
  79.        
  80.         public int getRowCount(){
  81.            
  82.             return data.length;
  83.         }
  84.        
  85.        
  86.         public String getColumnName(int col){
  87.            
  88.             return namaKolom[0];
  89.         }
  90.        
  91.        
  92.         public Object getValueAt(int row, int col){
  93.            
  94.             return data[row][col];
  95.         }
  96.        
  97.     }
  98.    
  99.    // class TabelPegawai extends AbstractTableModel{
  100.        
  101.        
  102.        
  103.        
  104.    
  105.    
  106.    
  107.    
  108.     public Tabel1() {
  109.         initComponents();
  110.        
  111.        
  112.        
  113.     }
  114.  
  115.     /**
  116.      * This method is called from within the constructor to initialize the form.
  117.      * WARNING: Do NOT modify this code. The content of this method is always
  118.      * regenerated by the Form Editor.
  119.      */
  120.     @SuppressWarnings("unchecked")
  121.     // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
  122.     private void initComponents() {
  123.  
  124.         jScrollPane1 = new javax.swing.JScrollPane();
  125.         jTable1 = new javax.swing.JTable();
  126.  
  127.         setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  128.  
  129.         jTable1.setModel(new javax.swing.table.DefaultTableModel(
  130.             new Object [][] {
  131.                 {null, null, null, null},
  132.                 {null, null, null, null},
  133.                 {null, null, null, null},
  134.                 {null, null, null, null}
  135.             },
  136.             new String [] {
  137.                 "Title 1", "Title 2", "Title 3", "Title 4"
  138.             }
  139.         ));
  140.         jScrollPane1.setViewportView(jTable1);
  141.  
  142.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  143.         getContentPane().setLayout(layout);
  144.         layout.setHorizontalGroup(
  145.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  146.             .addGroup(layout.createSequentialGroup()
  147.                 .addContainerGap()
  148.                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  149.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  150.         );
  151.         layout.setVerticalGroup(
  152.             layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
  153.             .addGroup(layout.createSequentialGroup()
  154.                 .addContainerGap()
  155.                 .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
  156.                 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  157.         );
  158.  
  159.         pack();
  160.     }// </editor-fold>                        
  161.  
  162.     /**
  163.      * @param args the command line arguments
  164.      */
  165.     public static void main(String args[]) {
  166.         /* Set the Nimbus look and feel */
  167.         //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
  168.         /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
  169.          * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
  170.          */
  171.         try {
  172.             for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
  173.                 if ("Nimbus".equals(info.getName())) {
  174.                     javax.swing.UIManager.setLookAndFeel(info.getClassName());
  175.                     break;
  176.                 }
  177.             }
  178.         } catch (ClassNotFoundException ex) {
  179.             java.util.logging.Logger.getLogger(Tabel1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  180.         } catch (InstantiationException ex) {
  181.             java.util.logging.Logger.getLogger(Tabel1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  182.         } catch (IllegalAccessException ex) {
  183.             java.util.logging.Logger.getLogger(Tabel1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  184.         } catch (javax.swing.UnsupportedLookAndFeelException ex) {
  185.             java.util.logging.Logger.getLogger(Tabel1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
  186.         }
  187.         //</editor-fold>
  188.  
  189.         /* Create and display the form */
  190.         java.awt.EventQueue.invokeLater(new Runnable() {
  191.             public void run() {
  192.                 new Tabel1().setVisible(true);
  193.             }
  194.         });
  195.     }
  196.  
  197.     // Variables declaration - do not modify                    
  198.     private javax.swing.JScrollPane jScrollPane1;
  199.     private javax.swing.JTable jTable1;
  200.     // End of variables declaration                  
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement