IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Composants Java Discussion :

Problème avec redimensionnement de celulle


Sujet :

Composants Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé Avatar de Tyrael62
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    90
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 90
    Par défaut Problème avec redimensionnement de celulle
    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
    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(); 
        }
    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
    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
     
    	}
    }
    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);
        }
      }
    }
    J'espère que vous pourrez m'éclairer ma lanterne en vous remerciant d'avance.

  2. #2
    Membre Expert
    Avatar de visiwi
    Profil pro
    Inscrit en
    Février 2008
    Messages
    1 052
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 1 052
    Par défaut
    Salut,

    Les "cellules de titres" ne sont pas des cellules de la JTable, mais du Header de la JTable.

    Tu peut récupérer cet objet par :
    getTableHeader()

    Tu y trouvera surement des méthodes pour le gérer comme tu le souhaite...

  3. #3
    Membre confirmé Avatar de Tyrael62
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    90
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 90
    Par défaut
    Merci mais apparemment , c'est pas ça , mes titres sont dans ma JTable , j'ai rien trouvé ou rien pu modifié dans le tableHeader

  4. #4
    Membre Expert
    Avatar de visiwi
    Profil pro
    Inscrit en
    Février 2008
    Messages
    1 052
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Février 2008
    Messages : 1 052
    Par défaut
    Effectivement je n'avais pas vue, mais tu fait un :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    grille.getTableHeader().setVisible(false);
    Visiblement pour demander a cette objet de t'afficher tes titres, il y a :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    actm = new AttributiveCellTableModel(totFiliere,titres);
    C'est donc du côté, je pense, qu'il faut regarder.

  5. #5
    Membre confirmé Avatar de Tyrael62
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    90
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 90
    Par défaut
    Je vais t'afficher tous les fichiers pour travailler sur les titres
    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
     
    import java.util.*;
    import java.awt.*;
    import javax.swing.table.*;
    import javax.swing.event.*;
     
    public class AttributiveCellTableModel extends DefaultTableModel {
     
      protected CellAttribute cellAtt;
    	/** {@docRoot} Modéle générique de tableau  */
      public AttributiveCellTableModel() {
        this((Vector)null, 0);
      }
    	/** {@docRoot} Constructeurs du modèle */
      public AttributiveCellTableModel(int numRows, int numColumns) {
        Vector names = new Vector(numColumns);
        names.setSize(numColumns);
        setColumnIdentifiers(names);
        dataVector = new Vector();
        setNumRows(numRows);
        cellAtt = new DefaultCellAttribute(numRows,numColumns);
     
      }
      public AttributiveCellTableModel(Vector columnNames, int numRows) {
        setColumnIdentifiers(columnNames);
        dataVector = new Vector();
        setNumRows(numRows);
        cellAtt = new DefaultCellAttribute(numRows,columnNames.size());
      }
     
      public AttributiveCellTableModel(Object[] columnNames, int numRows) {
        this(convertToVector(columnNames), numRows);
      }
      public AttributiveCellTableModel(Vector data, Vector columnNames) {
        setDataVector(data, columnNames);
      }
      public AttributiveCellTableModel(Object[][] data, Object[] columnNames) {
        setDataVector(data, columnNames);
      }
    	/** {@docRoot} Modification du vecteur donnée du tableau */
      public void setDataVector(Object[][] optOD, Object[] optDS) {
      Vector newData = convertToVector(optOD);
      Vector columnNames = convertToVector(optDS);
    	  if (newData == null)  throw new IllegalArgumentException("setDataVector() - Aucun parametres");
    	  // dataVector = new Vector(0);
        setColumnIdentifiers(columnNames);
        dataVector = newData;
        //
        cellAtt = new DefaultCellAttribute(dataVector.size(), columnIdentifiers.size());
        newRowsAdded(new TableModelEvent(this, 0, getRowCount()-1,
    		 TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
     
      }
    	/** {@docRoot} Retourne attribut cellule */
      public CellAttribute getCellAttribute() {
        return cellAtt;
      }
    	/** {@docRoot} Modifie attribut cellule */
      public void setCellAttribute(CellAttribute newCellAtt) {
        int numColumns = getColumnCount();
        int numRows    = getRowCount();
        if ((newCellAtt.getSize().width  != numColumns) ||
            (newCellAtt.getSize().height != numRows)) {
          newCellAtt.setSize(new Dimension(numRows, numColumns));
        }
        cellAtt = newCellAtt;
        fireTableDataChanged();
      }
    }
    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.awt.*;
    import java.awt.event.MouseListener;
     
     
    public class DefaultCellAttribute 
        //implements CellAttribute ,CellSpan  {
        implements CellAttribute ,CellSpan ,ColoredCell ,CellFont {
     
      protected int rowSize;
      protected int columnSize;
      protected int[][][] span;                   // CellSpan
      protected Color[][] foreground;             // ColoredCell
      protected Color[][] background;             //
      protected Font[][]  font;                   // CellFont
     
      public DefaultCellAttribute() {
        this(1,1);
      }
    	/** {@docRoot}  Définition des attributs des cellules pour interfaces */
      public DefaultCellAttribute(int numRows, int numColumns) {
        setSize(new Dimension(numColumns, numRows));
      }
     
      protected void initValue() {
        for(int i=0; i<span.length;i++) {
          for(int j=0; j<span[i].length; j++) {
    	span[i][j][CellSpan.COLUMN] = 1;
    	span[i][j][CellSpan.ROW]    = 1;
          }
        }
      }
     
    	/** {@docRoot}  Définition des attributs Zone sélectionnée 
             * retourne les coordonnées*/
      public int[] getSpan(int row, int column) {
        if (isOutOfBounds(row, column)) {
          int[] ret_code = {1,1};
          return ret_code;
        }
        return span[row][column];
      }
    	/** {@docRoot}  Définition des attributs Zone sélectionnée 
             * modifie les coordonnées*/
      public void setSpan(int[] span, int row, int column) {
        if (isOutOfBounds(row, column)) return;
        this.span[row][column] = span;
      }
    	/** {@docRoot}  Définition des attributs Zone sélectionnée 
             * retourne visibilité de la cellule*/
      public boolean isVisible(int row, int column) {
        if (isOutOfBounds(row, column)) return false;
        if ((span[row][column][CellSpan.COLUMN] < 1)
          ||(span[row][column][CellSpan.ROW]    < 1)) return false;
        return true;
      }
    	/** {@docRoot} 
             * fusion de deux cellules*/
      public void combine(int[] rows, int[] columns) {
        if (isOutOfBounds(rows, columns)) return;
        int    rowSpan  = rows.length;
        int columnSpan  = columns.length;
        int startRow    = rows[0];
        int startColumn = columns[0];
        for (int i=0;i<rowSpan;i++) {
          for (int j=0;j<columnSpan;j++) {
    	if ((span[startRow +i][startColumn +j][CellSpan.COLUMN] != 1)
    	  ||(span[startRow +i][startColumn +j][CellSpan.ROW]    != 1)) {
    	  return ;
    	}
          }
        }
        for (int i=0,ii=0;i<rowSpan;i++,ii--) {
          for (int j=0,jj=0;j<columnSpan;j++,jj--) {
    	span[startRow +i][startColumn +j][CellSpan.COLUMN] = jj;
    	span[startRow +i][startColumn +j][CellSpan.ROW]    = ii;
          }
        }
        span[startRow][startColumn][CellSpan.COLUMN] = columnSpan;
        span[startRow][startColumn][CellSpan.ROW]    =    rowSpan;
     
      }
    	/** {@docRoot}  Définition des attributs Zone sélectionnée 
             * retourne couleur premier plan */
      public Color getForeground(int row, int column) {
        if (isOutOfBounds(row, column)) return null;
        return foreground[row][column];
      }
    	/** {@docRoot}  Définition des attributs Zone sélectionnée 
             * modifie couleur arrière plan 1 cellule */
      public void setForeground(Color color, int row, int column) {
        if (isOutOfBounds(row, column)) return;
        foreground[row][column] = color;
      }
    	/** {@docRoot}  Définition des attributs Zone sélectionnée 
             * modifie couleur arrière plan plusieurs cellules */
      public void setForeground(Color color, int[] rows, int[] columns) {
        if (isOutOfBounds(rows, columns)){ return;}
        setValues(foreground, color, rows, columns);
      }
    	/** {@docRoot}  Définition des attributs Zone sélectionnée 
             * retourne couleur arrière plan */
      public Color getBackground(int row, int column) {
        if (isOutOfBounds(row, column)) return null;
        return background[row][column];
      }
    	/** {@docRoot}  Définition des attributs Zone sélectionnée 
             * modifie couleur arrière plan 1cellule*/
      public void setBackground(Color color, int row, int column) {
        if (isOutOfBounds(row, column)) return;
        background[row][column] = color;
      }
    	/** {@docRoot}  Définition des attributs Zone sélectionnée 
             * modifie couleur arrière plan plusieurs cellules */
      public void setBackground(Color color, int[] rows, int[] columns) {
        if (isOutOfBounds(rows, columns)) return;
        setValues(background, color, rows, columns);
      }
    	/** {@docRoot}  Définition des attributs Zone sélectionnée 
             *  retourne la police de la cellule*/
      public Font getFont(int row, int column) {
        if (isOutOfBounds(row, column)) return null;
        return font[row][column];
      }
    	/** {@docRoot}  Définition des attributs Zone sélectionnée 
             *  modifie la police de la cellule*/
      public void setFont(Font font, int row, int column) {
        if (isOutOfBounds(row, column)) return;
        this.font[row][column] = font;
      }
    	/** {@docRoot}  Définition des attributs Zone sélectionnée 
             *  retourne la police de la cellule*/
      public void setFont(Font font, int[] rows, int[] columns) {
        if (isOutOfBounds(rows, columns)) return;
        setValues(this.font, font, rows, columns);
      }
     
    	/** {@docRoot}  Retourne dimension selection */
     public Dimension getSize() {
        return new Dimension(rowSize, columnSize);
      }
    	/** {@docRoot}  Modifie dimension selection */
      public void setSize(Dimension size) {
        columnSize = size.width;
        rowSize    = size.height;
        span = new int[rowSize][columnSize][2];   // 2: COLUMN,ROW
        foreground = new Color[rowSize][columnSize];
        background = new Color[rowSize][columnSize];
        font = new Font[rowSize][columnSize];
        initValue();
      }
    	/** {@docRoot}  Retourne en dehors de la selection 1 cellule */
      protected boolean isOutOfBounds(int row, int column) {
        if ((row    < 0)||(rowSize    <= row)
          ||(column < 0)||(columnSize <= column)) {
          return true;
        }
        return false;
      }
    	/** {@docRoot}  Retourne en dehors de la selection plusieurs cellules */
      protected boolean isOutOfBounds(int[] rows, int[] columns) {
        for (int i=0;i<rows.length;i++) {
          if ((rows[i] < 0)||(rowSize <= rows[i])) return true;
        }
        for (int i=0;i<columns.length;i++) {
          if ((columns[i] < 0)||(columnSize <= columns[i])) return true;
        }
        return false;
      }
    	/** {@docRoot}  Modifs des valeurs */
      protected void setValues(Object[][] target, Object value,
                               int[] rows, int[] columns) {
        for (int i=0;i<rows.length;i++) {
          int row = rows[i];
          for (int j=0;j<columns.length;j++) {
    	  int column = columns[j];
    	  target[row][column] = value; }
        }
      }
    }
    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
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
     
    import java.awt.*;
    import java.math.BigDecimal;
    import java.text.DecimalFormat;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
     
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.border.*;
     
    public class AttributiveCellRendererRecap extends JLabel
        implements TableCellRenderer {
      protected static Border noFocusBorder;
    Projets pro;
      public int[] largeur;
      public CellSpan csp;
      public AttributiveCellTableModel opt;
     
      public AttributiveCellRendererRecap(AttributiveCellTableModel opt, Parametres param) {
        noFocusBorder = new EmptyBorder(0, 0, 0, 0);    
        setOpaque(true);
        setBorder(noFocusBorder);
        csp = (CellSpan)opt.getCellAttribute();
        largeur = enumLarg(opt); 
     
        //combineTitre(opt,csp);
        csp.combine(new int[]{0}, largeur);
        //csp.setBackground(Color.BLUE,new int[0],largeur);
        csp.combine(new int[]{1},new int[]{2,3,4,5,6});
        csp.combine(new int[]{1},new int[]{12,13,14,15}); 
     
        //Fusion des cellules de la dernière colonne
        for(int i=0;i<opt.getRowCount();i++){
        	if(!String.valueOf(opt.getValueAt(i,0)).contains("Niveau")){
        	csp.combine(new int[]{i},new int[]{opt.getColumnCount()-2,opt.getColumnCount()-1});
        	}
        }
     
      }
     
    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);
    			switch(row){
    			case 0:titre(row);break;
    			case 1:titre(row);break;
    			case 2:titre(1);break;
    			default:
    			setHorizontalAlignment(RIGHT);
    			setVerticalAlignment(CENTER);
    			break; }
    			if(column==0 && row !=0 )setHorizontalAlignment(LEFT);
    			//Alignement des données de la dernière colonne
    			if(column==table.getColumnCount()-2 && row>2)setHorizontalAlignment(CENTER);
          }
     
          if (cellAtt instanceof CellFont) {
    	  font = ((CellFont)cellAtt).getFont(row,column);
     
     
    	  //Police titre
    	  if(row == 0){
    		  ((CellFont)cellAtt).setFont(Font.decode("1px Arial Black Bold"), row, column);
    		  //cellAtt.setSize(new Dimension(64,30));
    	  }
          //Couleur et police entete
    	  if(row == 1 || row==2){
    		  value=String.valueOf("<html>"+table.getValueAt(row, column)+"</html>");
        	 cellAtt.setBackground((Color)Color.decode("#B0E0E6"),new int[]{row},largeur);  
    	     ((CellFont)cellAtt).setFont(Font.decode("1px Arial Black Bold"), row, column);
    	  }
    	  //Couleur et police lignes Niveau et total général
          if(row>2 && String.valueOf(table.getValueAt(row, column)).contains("Niveau")|| String.valueOf(table.getValueAt(row, column)).contains("Total Général")==true)
         	 {cellAtt.setBackground((Color)Color.decode("#FDF5E6"),new int[]{row},largeur);
             ((CellFont)cellAtt).setFont(Font.decode("1px Arial Black Bold"), new int[]{row},largeur);
     
             }
         //Fusion des cellules pour les lignes Niveau 
         if(row>2 && String.valueOf(table.getValueAt(row, column)).contains("Niveau")){
          csp.combine(new int[]{row},largeur);
          }
         //Couleur et police lignes total niveau
          if(String.valueOf(table.getValueAt(row, column)).contains("Total niveau")==true){
         	 cellAtt.setBackground((Color)Color.decode("#87CEEB"),new int[]{row},largeur);
             ((CellFont)cellAtt).setFont(Font.decode("1px Arial Black Bold"),new int[]{row},largeur);}
          }
     
          /*if(cellAtt instanceof CellSpan){
        	 CellSpan cls = (CellSpan)table.getModel();
        	 cls.combine(new int[]{1},new int[]{1,2,3,4,5,6});
          }*/
     
     
        }    
        if (isSelected ) {
          setForeground((foreground != null) ? foreground
                              : table.getSelectionForeground());
          setBackground(table.getSelectionBackground());
          table.setRowSelectionAllowed(true);
          //table.setColumnSelectionInterval(table.getSelectedRow(),table.getSelectedColumn()+5);
        }
        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;
      }
    /** {@docRoot}  Verification en console */
    public void lire_(Object[][] Topt) {
     for(int u = 0; u<Topt.length;u++){
    	for(int v = 0;v<Topt[0].length;v++){
    	 System.out.println("u:"+u+"v:"+v+" "+Topt[u][v]);
    	}
     }
    }
      private int[] getIntRow(TableModel model) {
    	int[] tmp = new int[model.getRowCount()];
    	int idx = 0;
    	while(idx<tmp.length){
    		tmp[idx] = idx;
    		idx++;
    	}
    	return tmp;
      }
     
      private void titre(int row) {
    	  switch(row){
    	  case 0:
    		  setHorizontalAlignment(CENTER);
    		  setVerticalAlignment(CENTER);		 
    	  break;
    	  case 1:
    		  setHorizontalAlignment(CENTER);
    		  setVerticalAlignment(CENTER);		 
    	  break;
     
    	  }
    	  repaint();
      }
     
    protected void setValue(Object value) {
        setText((value == null) ? "" : espaceDec(value.toString()));
      }
    private String espaceDec(String opt) {
    	StringBuffer tmpSB;
    	Matcher mat;
    	StringBuffer revS = new StringBuffer(opt+"");
        Pattern pat = Pattern.compile("([0-9]+).([0-9]+)");
    	if(estNbre(opt)){
    	revS = new StringBuffer(arrond(new BigDecimal(opt)));
        revS = revS.reverse();tmpSB = new StringBuffer();
        mat = pat.matcher(revS);
    	    while(mat.find()){
    	        	char c[] = mat.group(2).toCharArray();
    	        	for(int w=0;w<c.length;w++){
    	        		if(w % 3 == 0 && w!=0)tmpSB = tmpSB.append(" ");
    	        		tmpSB.append(c[w]); }
    	        	tmpSB = tmpSB.reverse();
    	        	StringBuffer decimal = new StringBuffer(mat.group(1));
     
    	        	tmpSB.append("."+decimal.reverse());
    	    }
        }
        else {
        	tmpSB = revS;
        }
    	return tmpSB.toString();
    }
     
    public static String arrond(BigDecimal tmp){
        DecimalFormat places = new DecimalFormat("0.00");
        String tmpS = places.format(tmp);
        tmpS.replaceAll(",",".");
        return tmpS;
    }
     
    private static boolean estNbre(String str){
    	try {Float.parseFloat(str);
    	return true; }
    	catch (NumberFormatException nfe){
    	return false; }
    	}
     
    private int[] enumLarg(AttributiveCellTableModel opt) {
        int[] tmp = new int[opt.getColumnCount()];
        for(int u = 0; u<opt.getColumnCount();u++){
        	tmp[u] = u;
        }
    	return tmp;
    	}
    }

  6. #6
    Membre confirmé Avatar de Tyrael62
    Profil pro
    Inscrit en
    Janvier 2006
    Messages
    90
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Janvier 2006
    Messages : 90
    Par défaut
    j'ai essayé un agrandissement de mes cellules dans la classe AttributiveCellRendererRecap mais même en passant dans la condition il m'agrandit toutes les cellules du tableau et le setRowHeight(int row , int rowHeight) passe pas du tout dans cette condition
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
     
          //Couleur et police entete
    	  if(row == 1 || row==2){
    		  value=String.valueOf("<html>"+table.getValueAt(row, column)+"</html>");
    		  table.setRowHeight(48);
        	 cellAtt.setBackground((Color)Color.decode("#B0E0E6"),new int[]{row},largeur);  
    	     ((CellFont)cellAtt).setFont(Font.decode("1px Arial Black Bold"), row, column);
    	  }
    Donc si quelqu'un à une solution alternative à ce problème , je suis tout ouie mais je vais quand même essayer de trouver une solution.

Discussions similaires

  1. [CSS 2.1] Problème avec position: fixed; lorsque la fenetre est redimensionnée
    Par chok371 dans le forum Mise en page CSS
    Réponses: 2
    Dernier message: 23/07/2010, 11h30
  2. Problèmes de DIV+FLOAT avec redimensionnement de fenêtre
    Par blbird dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 09/02/2009, 14h40
  3. Problème avec le redimensionnement
    Par Mike888 dans le forum Windows Forms
    Réponses: 3
    Dernier message: 06/11/2008, 17h18
  4. Problème de redimensionnement d'image avec CSS
    Par redvivi dans le forum Débuter
    Réponses: 4
    Dernier message: 24/03/2008, 11h28
  5. Problème avec redimensionnement tableau
    Par PoZZyX dans le forum Réseau
    Réponses: 18
    Dernier message: 20/04/2006, 15h46

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo