Bonjour à tous et toutes,
Voilà je suis actuellement en train de remettre en forme un tableau donc pour se faire , je gère l'écriture des titres sur plusieurs lignes.
Pour ce qui est des retours chariots , j'ai trouvé une méthode incluant les balises <html> , pas très beau je sais pas mais à raison de trouver mieux mais par contre là où je coince c'est pour redimensionner les celulles de titres.
Mon grille.setRowHeight(1,48) ne fonctionne pas du tout , bien qu'ayant cherché et encore cherché , je n'ai pas trouvé de solutions à mon problème.
Voici la partie concerné de ma classe Tableau
Et les deux parties qui , je pense sont la source de mon problème
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 public Tableau(Parametres param) { BorderLayout orientation=new BorderLayout(); setLayout(orientation); //Chargement des 2 tableaux à comparer recParam = param; exc = new Grille(recParam); proj= new Projets(recParam,0); totFilTmpO = exc.getGrille(0); totFilComO = exc.getGrille(1); //Suppression des filieres a masquer //Colo == //NbreLigne != totFilComO = padding(totFilTmpO,totFilComO); //Présentation colonnes à l'horizontale totFiliere = revers(totFilTmpO,exc.entete(recParam),exc.getTot(0)); totFiliereComp = revers(totFilComO,exc.entete(recParam),exc.getTot(1)); //Nombres de colonnes titres = new String[compte(exc.entete)];int idx = 0; while(idx<titres.length){titres[idx]=String.valueOf(idx);idx++;} //Application des données au modèle actm = new AttributiveCellTableModel(totFiliere,titres); grille = new MultiCase(actm,totFiliereComp,totFiliere); grille.setRowHeight(1,48); //Fusion des cellules format(); //Parametre mise en page du modèle //grille.setCellSelectionEnabled(true); //grille.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); ACR = new AttributiveCellRendererRecap(actm,recParam); //ACR = new AttributiveCellRendererTEST(); grille.setDefaultRenderer(Object.class, ACR); grille.setShowGrid(false); grille.getTableHeader().setVisible(false); grille.setVisible(true); grille.getTableHeader().setPreferredSize( new Dimension(grille.getSize().width, 0)); int min = exc.entete.length; //Ajustement du tableau AjusteColonne.autoResizeTable(grille,false,min); //Afficher les nouvelles filières en italique newFiliereItalic(proj,min); //grille.getColumnModel().getColumn(0).setMinWidth(200); grille.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); //formatTab = new FormatTab(exc,totFiliere); //grille = formatTab.getTab(); //Séparation du verticale du tableau //grille.addMouseListener(this); //grille.setBorder(JTable.) grilleFixe = (MultiCase)grille.clone(); //popupMenu.show(this,0,0); scroll = new JScrollPane(grille); scrollFixe = new JScrollPane(grilleFixe); scrollFixe.setPreferredSize(new Dimension(grille.getColumnModel().getColumn(0).getMinWidth(),grille.getHeight())); JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,scrollFixe,scroll); scroll.getVerticalScrollBar().setModel(scrollFixe.getVerticalScrollBar().getModel()); sp.setDividerSize(2); add(sp); repaint(); thr = new Thread(this); thr.start(); }
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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180 import java.util.*; import java.awt.*; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.print.PageFormat; import java.awt.print.Printable; import java.awt.print.PrinterException; import javax.swing.*; import javax.swing.table.*; import javax.swing.plaf.basic.*; import javax.swing.event.*; public class MultiCase extends JTable implements Cloneable,MouseListener { public MultiCase attr; public TableModel mod; int rowSouris,colSouris;//Coordonnées dans le tableau public JPopupMenu popupMenu; public Object[][] inf1,inf2; /** {@docRoot} Modéle du tableau * @param donnees * @param totFiliere */ public MultiCase(TableModel model, Object[][] don1, Object[][] don2) { super(model); mod = model; inf1 = don1; inf2 = don2; setUI(new MultiCaseUI()); tableHeader.setVisible(false); getTableHeader().setReorderingAllowed(false); setCellSelectionEnabled(true); setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); addMouseListener(this); } /** {@docRoot} Retourne coordonnées de la sélection */ public Rectangle getCellRect(int row, int column, boolean includeSpacing) { Rectangle sRect = super.getCellRect(row,column,includeSpacing); if ((row <0) || (column<0) || (getRowCount() <= row) || (getColumnCount() <= column)) { return sRect; } CellSpan cellAtt = (CellSpan)((AttributiveCellTableModel)getModel()).getCellAttribute(); if (! cellAtt.isVisible(row,column)) { int temp_row = row; int temp_column = column; row += cellAtt.getSpan(temp_row,temp_column)[CellSpan.ROW]; column += cellAtt.getSpan(temp_row,temp_column)[CellSpan.COLUMN]; } int[] n = cellAtt.getSpan(row,column); int index = 0; int columnMargin = getColumnModel().getColumnMargin(); Rectangle cellFrame = new Rectangle(); // int aCellHeight = rowHeight; int aCellHeight = rowHeight + rowMargin; cellFrame.y = row * aCellHeight; cellFrame.height = n[CellSpan.ROW] * aCellHeight; Enumeration enumeration = getColumnModel().getColumns(); while (enumeration.hasMoreElements()) { TableColumn aColumn = (TableColumn)enumeration.nextElement(); cellFrame.width = aColumn.getWidth() + columnMargin; if (index == column) break; cellFrame.x += cellFrame.width; index++; } for (int i=0;i<n[CellSpan.COLUMN]-1;i++) { TableColumn aColumn = (TableColumn)enumeration.nextElement(); cellFrame.width += aColumn.getWidth() + columnMargin; } if (!includeSpacing) { Dimension spacing = getIntercellSpacing(); cellFrame.setBounds(cellFrame.x + spacing.width/2, cellFrame.y + spacing.height/2, cellFrame.width - spacing.width, cellFrame.height - spacing.height); } return cellFrame; } /** {@docRoot} Retourne coordonnées ligne */ private int[] rowColumnAtPoint(Point point) { int[] retValue = {-1,-1}; int row = point.y / (rowHeight + rowMargin); if ((row <0)||(getRowCount() <= row)) return retValue; int column = getColumnModel().getColumnIndexAtX(point.x); CellSpan cellAtt = (CellSpan)((AttributiveCellTableModel)getModel()).getCellAttribute(); if (cellAtt.isVisible(row,column)) { retValue[CellSpan.COLUMN] = column; retValue[CellSpan.ROW ] = row; return retValue; } retValue[CellSpan.COLUMN] = column + cellAtt.getSpan(row,column)[CellSpan.COLUMN]; retValue[CellSpan.ROW ] = row + cellAtt.getSpan(row,column)[CellSpan.ROW]; return retValue; } /** {@docRoot} Retourne coordonnée ligne */ public int rowAtPoint(Point point) { return rowColumnAtPoint(point)[CellSpan.ROW]; } /** {@docRoot} Retourne coordonnée colonne */ public int columnAtPoint(Point point) { return rowColumnAtPoint(point)[CellSpan.COLUMN]; } /** {@docRoot} Raffraichie les valeurs (graph)*/ public void columnSelectionChanged(ListSelectionEvent e) { repaint(); } /** {@docRoot} Raffraichie les valeurs (données)*/ public void valueChanged(ListSelectionEvent e) { int firstIndex = e.getFirstIndex(); int lastIndex = e.getLastIndex(); if (firstIndex == -1 && lastIndex == -1) { // Selection cleared. repaint(); } Rectangle dirtyRegion = getCellRect(firstIndex, 0, false); int numCoumns = getColumnCount(); int index = firstIndex; for (int i=0;i<numCoumns;i++) { dirtyRegion.add(getCellRect(index, i, false)); } index = lastIndex; for (int i=0;i<numCoumns;i++) { dirtyRegion.add(getCellRect(index, i, false)); } repaint(dirtyRegion.x, dirtyRegion.y, dirtyRegion.width, dirtyRegion.height); } /** {@docRoot} Constructeurs d'un clone*/ public Object clone() { try { MultiCase obj = (MultiCase) super.clone(); return obj; } catch (CloneNotSupportedException e){ } return(null); } public void mouseClicked(MouseEvent e) { Point mousePoint = e.getPoint(); rowSouris = Math.round(rowAtPoint(mousePoint)); colSouris = Math.round(columnAtPoint(mousePoint)); //popupMenu = new PopMiniMenu(infos,rowSouris,colSouris,totFiliere,type[1]); popupMenu = new PopMiniMenu(inf1,rowSouris,colSouris,inf2,"1"); popupMenu.show(e.getComponent(), e.getX(), e.getY()); } public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub } public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub } public void mousePressed(MouseEvent e) { // TODO Auto-generated method stub } public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub } }J'espère que vous pourrez m'éclairer ma lanterne en vous remerciant d'avance.
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92 import java.util.*; import java.awt.*; import javax.swing.*; import javax.swing.table.*; import javax.swing.plaf.basic.*; public class MultiCaseUI extends BasicTableUI { /** {@docRoot} Interface d'un tableau */ public void paint(Graphics g, JComponent c) { Rectangle oldClipBounds = g.getClipBounds(); Rectangle clipBounds = new Rectangle(oldClipBounds); int tableWidth = table.getColumnModel().getTotalColumnWidth(); clipBounds.width = Math.min(clipBounds.width, tableWidth); g.setClip(clipBounds); int firstIndex = table.rowAtPoint(new Point(0, clipBounds.y)); int lastIndex = table.getRowCount()-1; Rectangle rowRect = new Rectangle(0,0, tableWidth, table.getRowHeight() + table.getRowMargin()); rowRect.y = firstIndex*rowRect.height; for (int index = firstIndex; index <= lastIndex; index++) { if (rowRect.intersects(clipBounds)) { paintRow(g, index); } rowRect.y += rowRect.height; } g.setClip(oldClipBounds); } /** {@docRoot} Retourne la forme du modéle de tableau */ private void paintRow(Graphics g, int row) { Rectangle rect = g.getClipBounds(); boolean drawn = false; AttributiveCellTableModel tableModel = (AttributiveCellTableModel)table.getModel(); CellSpan cellAtt = (CellSpan)tableModel.getCellAttribute(); int numColumns = table.getColumnCount(); for (int column = 0; column < numColumns; column++) { Rectangle cellRect = table.getCellRect(row,column,true); int cellRow,cellColumn; if (cellAtt.isVisible(row,column)) { cellRow = row; cellColumn = column; // System.out.print(" "+column+" "); // debug } else { cellRow = row + cellAtt.getSpan(row,column)[CellSpan.ROW]; cellColumn = column + cellAtt.getSpan(row,column)[CellSpan.COLUMN]; // System.out.print(" ("+column+")"); // debug } if (cellRect.intersects(rect)) { drawn = true; paintCell(g, cellRect, cellRow, cellColumn); } else { if (drawn) break; } } } /** {@docRoot} Retourne le type de tableau (Ratio,Subvention)*/ private void paintCell(Graphics g, Rectangle cellRect, int row, int column) { int spacingHeight = table.getRowMargin(); int spacingWidth = table.getColumnModel().getColumnMargin(); Color c = g.getColor(); g.setColor(table.getGridColor()); g.drawRect(cellRect.x,cellRect.y,cellRect.width-1,cellRect.height-1); g.setColor(c); cellRect.setBounds(cellRect.x + spacingWidth/2, cellRect.y + spacingHeight/2, cellRect.width - spacingWidth, cellRect.height - spacingHeight); if (table.isEditing() && table.getEditingRow()==row && table.getEditingColumn()==column) { Component component = table.getEditorComponent(); component.setBounds(cellRect); component.validate(); } else { TableCellRenderer renderer = table.getCellRenderer(row, column); Component component = table.prepareRenderer(renderer, row, column); if (component.getParent() == null) { rendererPane.add(component); } rendererPane.paintComponent(g, component, table, cellRect.x, cellRect.y, cellRect.width, cellRect.height, true); } } }
Partager