1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| import javax.swing.*;
public class Test extends JFrame {
/** Creates new form Test */
public Test() {
initComponents();
init();
}
private void initComponents() {
jScrollPane1 = new JScrollPane();
jTable1 = new JTable();
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
System.exit(0);
}
});
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);
getContentPane().add(jScrollPane1, java.awt.BorderLayout.CENTER);
pack();
}
private void init(){
for(int i=1;i<jTable1.getColumnModel().getColumnCount();i++){
jTable1.getColumnModel().getColumn(i).setPreferredWidth(15);
jTable1.getColumnModel().getColumn(i).setMaxWidth(15);
jTable1.getColumnModel().getColumn(i).setMinWidth(15);
jTable1.getColumnModel().getColumn(i).setResizable(false);
}
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
new Test().show();
}
// Variables declaration
private JScrollPane jScrollPane1;
private JTable jTable1;
} |
Partager