Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» Tuyệt Kỹ Đong Giai Chân Kinh (tuyệt Kỹ cua trai)
Thu Aug 23, 2012 5:38 am by Admin

» Tuyệt kỹ cua giai
Thu Aug 23, 2012 5:36 am by Admin

» NETCAT.........
Mon Aug 13, 2012 6:35 am by Admin

» Bảo mật CSDL bằng phương pháp mã hóa.
Tue Apr 17, 2012 10:04 pm by Admin

» Hàm mã hóa MD5 bằng JavaScript
Tue Apr 17, 2012 10:03 pm by Admin

» Giá của món quà
Fri Apr 13, 2012 6:01 am by Admin

» Sẽ chỉ yêu ai?
Fri Apr 13, 2012 6:01 am by Admin

» Cách đọc bảng chữ cái!
Thu Apr 12, 2012 10:37 pm by Admin

» Gắn trojan, keylog, virus vào website, forum
Tue Apr 10, 2012 1:14 am by Admin

Shopmotion


Affiliates
free forum


Demo Jtable

View previous topic View next topic Go down

Demo Jtable

Post  Admin on Wed Jun 15, 2011 12:16 pm

package temp;

import javax.swing.DefaultCellEditor;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;

/**
*
* @author Johto
*/
public class Demo_jtable extends javax.swing.JFrame {

/** Creates new form Demo_jtable */
public Demo_jtable() {
initComponents();
set_data();
}
public void set_data()
{
JCheckBox check=new JCheckBox();
JComboBox com=new JComboBox();
com.addItem("Sinh viên");
com.addItem("Giáo Viên");
com.addItem("Học sinh");
com.addItem("Nhân viên văn phòng");
com.addItem("Khác");
DefaultCellEditor de=new DefaultCellEditor(check);
DefaultCellEditor de2=new DefaultCellEditor(com);
bang1.getColumnModel().getColumn(1).setCellEditor(de);
bang1.getColumnModel().getColumn(2).setCellEditor(de2);
}
/** 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")
// //GEN-BEGIN:initComponents
private void initComponents() {

jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
bang1 = new javax.swing.JTable();
jButton1 = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
bang2 = new javax.swing.JTable();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("Demo Jtable congdongjava.com");

jPanel1.setBackground(new java.awt.Color(219, 226, 242));
jPanel1.setToolTipText("Demo Jtable congdongjava.com");

jLabel1.setFont(new java.awt.Font("Tahoma", 2, 18));
jLabel1.setForeground(new java.awt.Color(0, 153, 102));
jLabel1.setText("Demo Jtable congdongjava.com");

bang1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null}
},
new String [] {
"Họ và tên", "Giới tính", "Nghề nghiệp"
}
));
jScrollPane1.setViewportView(bang1);

jButton1.setText("Cập nhật giá trị của Jtable trên");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});

bang2.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null},
{null, null, null}
},
new String [] {
"Họ và tên", "Giới tính", "Nghề nghiệp"
}
) {
boolean[] canEdit = new boolean [] {
false, false, false
};

public boolean isCellEditable(int rowIndex, int columnIndex) {
return canEdit [columnIndex];
}
});
jScrollPane2.setViewportView(bang2);

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap(139, Short.MAX_VALUE)
.addComponent(jLabel1)
.addGap(128, 128, 128))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(171, 171, 171)
.addComponent(jButton1)
.addContainerGap(167, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 487, Short.MAX_VALUE))
.addContainerGap(22, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(20, 20, 20)
.addComponent(jLabel1)
.addGap(18, 18, 18)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 131, Short.MAX_VALUE)
.addContainerGap())
);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);

pack();
}//
//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
for (int i = 0; i < bang1.getRowCount(); i++) {
for (int j = 0; j < bang1.getColumnCount(); j++) {
bang2.setValueAt(bang1.getValueAt(i, j),i,j);

}

}
}//GEN-LAST:event_jButton1ActionPerformed

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Demo_jtable().setVisible(true);
}
});
}

// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTable bang1;
private javax.swing.JTable bang2;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
// End of variables declaration//GEN-END:variables

}

Admin
Admin

Tổng số bài gửi : 782
Join date : 2009-08-15

View user profile http://hackis.forumotion.com

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum