| 12
 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
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 
 |  
         import javax.swing.SwingUtilities;
import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Rectangle;
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JScrollPane;
import javax.swing.table.DefaultTableModel;
import java.awt.Font;
import javax.swing.JTable;
public class test  extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
DefaultTableModel tableModel;
Object[][] donnees = {  {"","","","","",""}} ;
String[] titreColonnes = {"nom", "prénom","adresse"};
private JScrollPane jScrollPane = null;
private JTable jTable = null;
private JScrollPane getJScrollPane() {
if (jScrollPane == null) {
jScrollPane = new JScrollPane();
jScrollPane.setBounds(new Rectangle(65, 101,350, 120));
jScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
jScrollPane.setBackground(Color.orange);
 jScrollPane.setBorder(null);
jScrollPane.setFont(new Font("Dialog", Font.PLAIN, 12));
 jScrollPane.setViewportView(getJTable());
jScrollPane.setForeground(Color.orange);	      
}
return jScrollPane;
	}
private JTable getJTable() {
if (jTable == null) {
tableModel = new DefaultTableModel(donnees, titreColonnes);
jTable = new JTable(tableModel)  {
public boolean isCellEditable(int rowIndex, int vColIndex) {
return false;
 }
  }; 
 jTable.setBackground(Color.orange);
jTable.setIntercellSpacing(new Dimension(2, 1));
jTable.setRowHeight(24);
jTable.setFont(new Font("Arial", Font.PLAIN, 14));
jTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
 jTable.getColumnModel().getColumn(0).setPreferredWidth(80);
 jTable.getColumnModel().getColumn(1).setPreferredWidth(80);
jTable.getColumnModel().getColumn(2).setPreferredWidth(80);
}
return jTable;
	}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
test thisClass = new test();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
thisClass.setResizable (false);
thisClass.setLocationRelativeTo(null);
}
});
}
public test() {
super();
initialize();
}
private void initialize() {
this.setSize(580, 320);
this.setBackground(new Color(0, 138, 255));
this.setContentPane(getJContentPane());
this.requestFocus();
	}
private JPanel getJContentPane() {
if (jContentPane == null) {
	jContentPane = new JPanel();
	jContentPane.setLayout(null);
	jContentPane.setBackground(new Color(0, 138, 255));
	jContentPane.add(getJScrollPane(), null);
	}
	return jContentPane;
	}
 
} | 
Partager