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
|
package test;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.BorderFactory;
import javax.swing.JDialog;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
public class Exemple extends JDialog
{
private static final long serialVersionUID = 1L;
private JTable Table = null;
private DefaultTableModel modelTable = null;
private JScrollPane scrollTable = null;
private javax.swing.JButton Terminer = null;
public Exemple()
{
super();
initialisation();
}
private void initialisation()()
{
setSize(585, 419);
getRootPane().setBorder( BorderFactory.createLineBorder(Color.RED) );
javax.swing.JPanel ContentPane= new javax.swing.JPanel();
ContentPane.setName("ContentPane");
ContentPane.setLayout(null);
Terminer = new javax.swing.JButton();
Terminer.setName("Terminer");
Terminer.setText("Terminer");
Terminer.setBounds(199, 305, 91, 25);
Terminer.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e){System.exit(0);}});
Table = new JTable();
/*
{
private static final long serialVersionUID = 1L;
public boolean editCellAt(int row, int column, java.util.EventObject e)
{
return false;
}
};
*/
Table.addMouseListener(new MouseAdapter()
{
@Override
public void mouseClicked(MouseEvent me)
{
if (me.getClickCount() == 1)System.out.println("Simple click " );
else System.out.println("Double click " );
}
});
scrollTable= new JScrollPane();
scrollTable.setViewportView(Table);
scrollTable.setBounds(40, 90, 472, 175);
scrollTable.setViewportView(Table);
ContentPane.setBackground(java.awt.Color.black);
ContentPane.add(Terminer, Terminer.getName());
ContentPane.add(scrollTable);
setContentPane(ContentPane);
execute();
this.setLocationRelativeTo(null);
this.setVisible(true);
}
private void execute()
{
Object[] tableHeader = new Object[]{"mes valeurs"};
modelTable = new DefaultTableModel(tableHeader, 0);
modelTable.setRowCount(10);
modelTable.setColumnCount(1);
Table.setModel(modelTable);
JTableHeader header = Table.getTableHeader();
header.setBackground(java.awt.Color.yellow);
Table.setRowHeight(20);
Table.setShowGrid(true);
for (int i=0;i<3 ; i++) modelTable.insertRow(i, new Object[]{" Ligne " + i, });
}
public static void main(java.lang.String[] args)
{
new Exemple( ).execute();;
}
} |
Partager