Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package latihan29;
- import javax.swing.DefaultCellEditor;
- import javax.swing.JComboBox;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import javax.swing.JTable;
- import javax.swing.table.AbstractTableModel;
- import javax.swing.table.DefaultTableCellRenderer;
- import javax.swing.table.TableCellRenderer;
- import javax.swing.table.TableColumn;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.GridLayout;
- /**
- *
- * @author steven
- *
- * Referensi Pendukung: http://kodejava.org/how-do-i-render-boolean-value-as-checkbox-in-jtable-component/
- */
- public class Tabel1 extends javax.swing.JFrame {
- /**
- * Creates new form Tabel1
- */
- /**
- * Menciptakan tabel model
- *
- */
- class TabelPegawaiModel extends AbstractTableModel{
- // super("Tabel Pegawai");
- String[] namaKolom = {"Nama Pegawai","CheckList"};
- Object[][] data = {
- {"Steven Nathaniel", new Boolean(true)},
- {"Bill Gates", new Boolean(true)}
- };
- public void setValueAt(Object value, int row, int col){
- data[row][col] = value;
- super.setValueAt(value, row, col);
- }
- // @Override
- public int getColumnCount(){
- return namaKolom.length;
- }
- public int getRowCount(){
- return data.length;
- }
- public String getColumnName(int col){
- return namaKolom[col];
- }
- public Object getValueAt(int row, int col){
- return data[row][col];
- }
- //public Class<?> getColumnClass(int col){
- // return data[0][col].getClass();
- // return data[0] [col].getClass();
- // if(col == 1)
- // return Boolean.class;
- // else
- // return Object.class;
- // }
- public Class getColumnClass(int c){
- return getValueAt(1, c).getClass();
- }
- public boolean isCellEditable(int row, int col){
- // sesuaikan angka kolom dengan angka kolom yg akan bisa di edit
- if(col == 2)
- return false;
- else
- return true;
- }
- }
- // class TabelPegawai extends AbstractTableModel{
- public Tabel1() {
- initComponents();
- TabelPegawaiModel tabel1 = new TabelPegawaiModel();
- jTable1.setModel(tabel1);
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jScrollPane1 = new javax.swing.JScrollPane();
- jTable1 = new javax.swing.JTable();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- jTable1.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- {null, null, null, null},
- {null, null, null, null},
- {null, null, null, null},
- {null, null, null, null}
- },
- new String [] {
- "Title 1", "Title 2", "Title 3", "Title 4"
- }
- ));
- jScrollPane1.setViewportView(jTable1);
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- );
- pack();
- }// </editor-fold>
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(Tabel1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(Tabel1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(Tabel1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(Tabel1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new Tabel1().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JTable jTable1;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement