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

AWT/Swing Java Discussion :

Fusion de cellule :-/


Sujet :

AWT/Swing Java

  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    115
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Juillet 2005
    Messages : 115
    Par défaut Fusion de cellule :-/
    Edit:

    Alors désolé si je n'est pas été clair, donc je repose ma question.

    J'utilise une JTable pour afficher des données. Ma JTable est composée de 2 colonnes et de n lignes ajoutées par l'utilisateur. La première colonne représente un libellé de question et la deuxième, les modalités de réponses. Mais l'utilisateur a également la possibilité d'ajouter un titre dans ma JTable qui doit apparaitre sur une seule ligne. Je dois donc fusionner les deux colonnes pour avoir une seule ligne ou j'ajoute mon titre.

    Je crois que pour cela il faut redéfinir le paint de ma table, mais je ne comprends pas exactement comment faire.

    J'ai trouvé différents exemple dont celui ci que je suis en train d'essayer de modifier sans succès...
    http://forum.java.sun.com/thread.jsp...sageID=1929636

    voila le code de ma modife:
    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
    /*
     * FusionTableUI.java
     *
     * Created on 12. octobre 2006, 11:31
     *
     * To change this template, choose Tools | Template Manager
     * and open the template in the editor.
     */
     
    package dmind.ihm;
     
    import ihm.Ihm_creation_questionnaire;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import javax.swing.plaf.basic.*;
     
     
    /**
     * @version 1.0 11/26/98
     */
     
    public class FusionTableUI extends BasicTableUI {
     
        public void paint(Graphics g, JComponent c) {
    //get the rectangle bounds of the current graphic to be drawn
            Rectangle oldClipBounds = g.getClipBounds();
    //makes a new rectangle the same size as the current rectangle
            Rectangle clipBounds = new Rectangle(oldClipBounds);
    //gets the width of all combined columns and assigns to tableWidth
            int tableWidth = table.getColumnModel().getTotalColumnWidth();
    //sets the width of the new rectangle to equal the either the current rect size of the table width
            clipBounds.width = Math.min(clipBounds.width, tableWidth);
    //Sets the current clip to the rectangle specified by the given coordinates
            g.setClip(clipBounds);
     
    //define the first and last rows that are visible
            int firstIndex = table.rowAtPoint(new Point(0, clipBounds.y));
            int lastIndex = table.getRowCount()-1;
     
    //define a rowRect. This is a rectangle spanning the entire visible part of the table
            Rectangle rowRect = new Rectangle(0,0,tableWidth, table.getRowHeight() + table.getRowMargin());
     
            rowRect.y = firstIndex*rowRect.height;
     
    //for every row that is visible, paint it
            for (int index = firstIndex; index <= lastIndex; index++) {
    //is the clipBounds of the current object to be drawn in this row?
                if (rowRect.intersects(clipBounds)) {
                    paintRow(g, index);
                }
    //move to next row
                rowRect.y += rowRect.height;
            }
            g.setClip(oldClipBounds);
        }
     
        private void paintRow(Graphics g, int row) {
    //define rect as the current graphic objects bounds
            Rectangle rect = g.getClipBounds();
    //the graphic has not been drawn yet
            boolean drawn = false;
    //define how many columns we have to draw for this row
            int numColumns = table.getColumnCount();
     
    //for every column in the row, paint it
            for (int column = 0; column < numColumns; column++) {
    //define cellRect
                Rectangle cellRect = table.getCellRect(row,column,true);
                int cellRow;
                int cellColumn;
     
                cellRow = row;
                cellColumn = column;
     
                if (cellRect.intersects(rect)) {
                    drawn = true;
     
                    try {
    //is this a statement row? If so, apply special treatment to the cell,
    //otherwise paint the cell normally
                        if (Ihm_creation_questionnaire.fusion) {
    //We are on a row we want to span. If its the 1st column, increase
    //the width of the rectangle to span the entire table width and
    //call paintCell. Otherwise, do not even paint the cell.
                            if (cellColumn==0) {
                                cellRect.width=table.getColumnModel().getTotalColumnWidth();
                                paintCell(g, cellRect, cellRow, cellColumn);
                            }
                        } else
                            paintCell(g, cellRect, cellRow, cellColumn);
                    } catch(Exception e) {
                        e.printStackTrace();
                    }
                } else {
                    if (drawn)
                        break;
                }
            }
        }
     
     
        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);
            }
        }
    }

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    115
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Juillet 2005
    Messages : 115
    Par défaut
    Me dites pas que personne ne peut m'aider!!

  3. #3
    Membre éprouvé
    Avatar de Deadpool
    Homme Profil pro
    Inscrit en
    Novembre 2005
    Messages
    1 312
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations forums :
    Inscription : Novembre 2005
    Messages : 1 312
    Par défaut
    Ben ta question n'est absolument pas claire.

    A vrai dire on ne sait même pas de quoi tu parle.

    Tu veux fusionner des cellules, ok, mais dans quoi? Dans une JTable? Dans une feuille Excel?

    Précise le contexte et surtout ce qui te pose problème, sur quoi tu bloque, et là on pourra t'aider.

  4. #4
    Membre expérimenté Avatar de Betatesteur
    Inscrit en
    Juillet 2003
    Messages
    210
    Détails du profil
    Informations forums :
    Inscription : Juillet 2003
    Messages : 210
    Par défaut
    Hello,
    Citation Envoyé par delma
    un petit up...
    de quoi?

    Citation Envoyé par Descent
    Ben ta question n'est absolument pas claire.

    A vrai dire on ne sait même pas de quoi tu parle.

    Tu veux fusionner des cellules, ok, mais dans quoi? Dans une JTable? Dans une feuille Excel?

    Précise le contexte et surtout ce qui te pose problème, sur quoi tu bloque, et là on pourra t'aider.
    d'abord répondre à ça...


    @++

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Juillet 2005
    Messages
    115
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Juillet 2005
    Messages : 115
    Par défaut
    J'y ai répondu en éditant le permier post... c'est toujours pas clair??

Discussions similaires

  1. [VB.NET2003][Framework 2.0] Fusion de cellule
    Par b_lob dans le forum Windows Forms
    Réponses: 8
    Dernier message: 06/04/2006, 11h06
  2. [Swing][JTable]Fusion des cellules d'un tableau
    Par LordBlaize dans le forum Composants
    Réponses: 1
    Dernier message: 23/03/2006, 18h48
  3. [JTable]Fusion de cellules
    Par vincent63 dans le forum Composants
    Réponses: 6
    Dernier message: 13/02/2006, 14h28
  4. [VB6] Problème MsFlexgrid et Fusion des cellules
    Par dubidon dans le forum VB 6 et antérieur
    Réponses: 2
    Dernier message: 07/02/2006, 09h00
  5. [VBA-E] Fusion de cellule
    Par Nicos77 dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 29/07/2004, 13h24

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