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 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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
String[] columnNames = {"REZ","COL2"};
final DefaultTableModel dtm = new DefaultTableModel();
/* Vector entete = new Vector();*/
Vector reqJoue = new Vector();
dtm.setColumnIdentifiers(columnNames);
dtm.addRow(columnNames);
JLabel lb_fichier = new JLabel("Fichier source : ");
lb_fichier.setHorizontalAlignment(SwingConstants.CENTER);
lb_fichier.setBounds(10, 45, 95, 23);
panel_2.add(lb_fichier);
JButton btnNewButton_2 = new JButton("New button");
btnNewButton_2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final JFileChooser fc = new JFileChooser();
int response = fc.showOpenDialog(frame);
String [] tab = new String[1000];
String limit = ";select";
String str = "";
int i = 0;
if (response == JFileChooser.APPROVE_OPTION)
{
String filename = fc.getSelectedFile().toString();
text_file_name.setText(filename);
try {
Scanner scanner=new Scanner(new File(filename));
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
tab[i] = line;
str = str + line;
i = i + 1;
}
scanner.close();
String query;
String[] values = str.split(";select");
for (int j=0; j<values.length; j++) {
Vector reqJoue = new Vector();
if (j == 0)
{
query = " " + values[j];
}
else
{
query = "select " + values[j];
}
try {
String a = execution.selectRecordsFromTable(query,j);
reqJoue.addElement(a);
reqJoue.addElement(query);
dtm.addRow(reqJoue);
} catch (SQLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
});
btnNewButton_2.setBounds(10, 11, 89, 23);
panel_2.add(btnNewButton_2);
table = new JTable();
table.getTableHeader().setBackground(Color.GRAY);
table.setModel(dtm);
table.setColumnSelectionAllowed(true);
table.setCellSelectionEnabled(true);
table.setBounds(122, 111, 378, 201);
table.setDefaultRenderer(Object.class, new jTableRender());
panel_2.add(table);
//panel_2.add(new JScrollPane(table), BorderLayout.CENTER);
text_file_name = new JTextField();
text_file_name.setBounds(120, 45, 420, 23);
panel_2.add(text_file_name);
text_file_name.setColumns(10);
}
public class jTableRender extends DefaultTableCellRenderer {
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
/* final TableColumnModel columnModel = table.getColumnModel();
columnModel.getColumn(1).setWidth(100);*/
Object o = table.getValueAt(row, column);
if (o != null && component instanceof JLabel)
{
JLabel label = (JLabel) component;
if (label.getText().contains("KO"))
{
component.setBackground(Color.red);
}
else if (label.getText().contains("OK"))
component.setBackground(Color.green);
else
component.setBackground(Color.white);
}
return component;
}
} |
Partager