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 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
public class TranslateModeTableDialog extends JDialog implements ActionListener{
private static final String CT_TITLE = "Test";
private JTable FTable;
public TranslateModeTableDialog(Frame AParent, List DataTranslateList){
super(AParent,CT_TITLE,true);
setResizable(false);
setLocationRelativeTo(null);
Container lcontenu = getContentPane();
lcontenu.setLayout(new BorderLayout());
//Panel "OK / Cancel"
createValidationPanel(lcontenu);
//Création du panel principal
int ly = getFheightBorder();
JPanel lPanelCenter = new JPanel();
lcontenu.add(lPanelCenter, BorderLayout.CENTER);
String[] columnNames = {"ITEM", "KEY",
COL,COL EDITABLE};
Object[][] data = new Object[DataTranslateList.size()][4];
//Ajout des donnees à data
//....
FTable = new JTable(new MyTableModel(data,columnNames));
Color lColor = lPanelCenter.getBackground().darker();
FTable.getColumnModel().getColumn(0).setCellRenderer(new MyCellRendererColor(lColor.darker()));
FTable.getColumnModel().getColumn(1).setCellRenderer(new MyCellRendererColor(lColor));
FTable.getColumnModel().getColumn(2).setCellRenderer(new MyCellRendererColor(lColor.brighter()));
FTable.getColumnModel().getColumn(3).setCellRenderer(new MyCellRenderer());
FTable.setRowHeight(getFHeightComponent());
}
lPanelCenter.setLayout(new BorderLayout());
lPanelCenter.add(FTable.getTableHeader(), BorderLayout.PAGE_START);
lPanelCenter.add(FTable, BorderLayout.CENTER);
setSize(getFwidth(),getFHeight(lDataTranslateNb,FTable.getTableHeader().getHeight()));
}
/**
* Permet d'ajouter le panel "OK / Cancel"
*
* @param AContenuDialog
* @return : le panel de validation contenant les deux boutons
*/
private JPanel createValidationPanel(Container AContenuDialog){
JPanel lpanel = new JPanel();
lpanel.setPreferredSize(new Dimension(400,50));
lpanel.setLayout(null);
AContenuDialog.add(lpanel,BorderLayout.SOUTH);
//Je crée deux boutons
//.....
return lpanel;
}
/**************************************************************************************
* Gestion des tailles fixes des composants
**************************************************************************************/
/**Largeur du dialog*/
private final int getFwidth(){
return 400;
}
/**Hauteur du dialog*/
private final int getFHeight(int AComponentNb, int AHeaderHeight){
return AComponentNb * getFHeightComponent() + AHeaderHeight + 100;
}
/**Largeur de l'espace de bordure des panels principaux*/
private final int getFwidthBorder(){
return 16;
}
/**Hauteur de l'espace de bordure des panels principaux*/
private final int getFheightBorder(){
return 16;
}
/**Hauteur des composants */
private final int getFHeightComponent(){
return 50;
}
/**Largeur des composants */
private final int getFWidthComponent(){
return 170;
}
/**************************************************************************************
* MyTableModel
**************************************************************************************/
private class MyTableModel extends DefaultTableModel{
public MyTableModel(Object[][] data, Object[] columnNames) {
super(data, columnNames);
}
public boolean isCellEditable(int row, int col) {
if (col == 3) {
return true;
} else {
return false;
}
}
}
/**************************************************************************************
* MyCellRendererColor
**************************************************************************************/
public class MyCellRendererColor extends MyCellRenderer {
private Color FcolorBackground = null;
public MyCellRendererColor(Color AcolorBackground){
FcolorBackground = AcolorBackground;
}
public Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component c = super.getTableCellRendererComponent (table, value, isSelected, hasFocus, row, column);
c.setBackground(FcolorBackground);
return c;
}
}
/**************************************************************************************
* MyCellRenderer
**************************************************************************************/
public class MyCellRenderer extends DefaultTableCellRenderer {
public void setValue(Object value) {
setText((value == null) ? "" : "<html>"+value.toString()+"</html>");
}
}
} |
Partager