Bonjour les java.dév !!!
J'ai rencontré un petit soucis avec JTable...
Le problème est de Fusionner quelques cellules.
voilà le code de mon JTable :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
T= new JTable(Cd); //Cd est un DefaultTableModel
 
		T=(JTable) A.getTableCellRendererComponent(T, "2", false, true, 1, 20
				);
		T.setRowHeight(25);
		T.setAutoscrolls(true);
		T.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
		JScrollPane PH = new JScrollPane(T);
		T.getTableHeader().setPreferredSize(new Dimension(5000, 50));
		getContentPane().add(PH, BorderLayout.SOUTH);
	setVisible(false);
	setVisible(true);
Bon j'ai fait une petite recherche sur et enfin j'ai récupéré le code à partir de ce lien http://www.codeguru.com/java/articles/139.shtml

Voici la classe responsable des modifications recherchées (d'après ce que j'ai compris)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
import java.awt.*;
import java.net.MalformedURLException;
 
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;
 
import Défaut.MenuMBRD;
 
 
/**
 * @version 1.0 11/22/98
 */
public class AttributiveCellRenderer extends JLabel
    implements TableCellRenderer {
  protected static Border noFocusBorder; 
 
  public AttributiveCellRenderer() {
    noFocusBorder = new EmptyBorder(1, 2, 1, 2);
    setOpaque(true);
    setBorder(noFocusBorder);  
  }
 
  public Component getTableCellRendererComponent(JTable table, Object value,
                 boolean isSelected, boolean hasFocus, int row, int column) {
    Color foreground = null;
    Color background = null;
    Font font = null;
    TableModel model = table.getModel();
    if (model instanceof AttributiveCellTableModel) {
      CellAttribute cellAtt = ((AttributiveCellTableModel)model).getCellAttribute();
      if (cellAtt instanceof ColoredCell) {
	foreground = ((ColoredCell)cellAtt).getForeground(row,column);
	background = ((ColoredCell)cellAtt).getBackground(row,column);
      }
      if (cellAtt instanceof CellFont) {
	font = ((CellFont)cellAtt).getFont(row,column);
      }
    }
    if (isSelected) {
      setForeground((foreground != null) ? foreground
                          : table.getSelectionForeground());
      setBackground(table.getSelectionBackground());
    } else {
      setForeground((foreground != null) ? foreground 
			  : table.getForeground());
      setBackground((background != null) ? background 
			  : table.getBackground());
    }
    setFont((font != null) ? font : table.getFont());
 
    if (hasFocus) {
      setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") );
      if (table.isCellEditable(row, column)) {
	setForeground((foreground != null) ? foreground
	              : UIManager.getColor("Table.focusCellForeground") );
	setBackground( UIManager.getColor("Table.focusCellBackground") );
      }
    } else {
      setBorder(noFocusBorder);
    }
    setValue(value);        
    return this;
  }
 
  protected void setValue(Object value) {
    setText((value == null) ? "" : value.toString());
  } 
}
Mais j'ai pas pu l'utiliser...
Normalement je dois instancier une variable de cette classe puis affecter le JTable dans la méthode
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
 public Component getTableCellRendererComponent(JTable table, Object value,
                 boolean isSelected, boolean hasFocus, int row, int column)
de la classe AttributiveCellRenderer...
Alors j'ai fait cela :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
	T=(JTable) A.getTableCellRendererComponent(T,null, false, true, 1, 18);
Mais ça fonctionne pas
On m'affiche une erreur :
IWAV0052E Invocation Target Exception creating Gamme.RévParProd
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:494)
at org.eclipse.ve.internal.java.vce.launcher.remotevm.JFCLauncher.launch(JFCLauncher.java:56)
at org.eclipse.ve.internal.java.vce.launcher.remotevm.JavaBeansLauncher.main(JavaBeansLauncher.java:77)
Caused by: java.lang.ClassCastException: table.AttributiveCellRenderer
at Gamme.RévParProd.<init>(RévParProd.java:76)
... 6 more
Merci pour vos idées.