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 :

Mettre deux JScrollPane dans un JTable


Sujet :

Composants Java

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    28
    Détails du profil
    Informations personnelles :
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Octobre 2009
    Messages : 28
    Points : 23
    Points
    23
    Par défaut Mettre deux JScrollPane dans un JTable
    Bonjour à tous,
    Je recherche un moyen de mettre deux JScrollPane dans un JTable et de plus rajouter un ligne de commentaire dans les colonnes fixes.

  2. #2
    Expert éminent sénior
    Avatar de sinok
    Profil pro
    Inscrit en
    Août 2004
    Messages
    8 765
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Août 2004
    Messages : 8 765
    Points : 12 977
    Points
    12 977
    Par défaut
    A quel niveau cherches tu à mettre le second JScrollPäne?

    Tu cherches à avoir des colonnes fixes?

    Dans ce cas là ça se fait très bien avec un unique JScrollPane et deux JTable.
    Une JTable contenant les colonnes fixes que l'on va placer dans le rowHeader du JScrollPane et le reste des colonnes que l'on mettra dans la seconde JTable que l'on placera dans le viewport du JScrollPane.

    (fais une recherche sur JTable colonne fixe dans le forum, il y a un paquet de posts à ce sujet qui traînent).
    Hey, this is mine. That's mine. All this is mine. I'm claiming all this as mine. Except that bit. I don't want that bit. But all the rest of this is mine. Hey, this has been a really good day. I've eaten five times, I've slept six times, and I've made a lot of things mine. Tomorrow, I'm gonna see if I can't have sex with something.

  3. #3
    Membre à l'essai
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    28
    Détails du profil
    Informations personnelles :
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Octobre 2009
    Messages : 28
    Points : 23
    Points
    23
    Par défaut
    J'ai trouvé comment faire mes JScrollPane mais j'ai un nouveau problème. Je cherche le moyen de mettre un commentaire sur le bords de la fenêtre de gauche du JTable.
    Je souhaite indiquer les numéro de la matrice qui va de 1 à n.
    Voici mon code :
    package tablePixel;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.*;
    /**
    * Table Pixel
    * @author Dimitri PIANETA
    * @see dimitri.pianeta@gmail.com
    * @version 1
    */
    public class Table3 {


    public Table3(String value[][]){
    JFrame frame = new JFrame("Table Pixel");
    JPanel panel = new JPanel();

    int h = value.length;
    int w = value[0].length;
    String[] col = new String[h];
    String[] rows = new String[w];

    for (int i = 0; i<h; i++){
    col[i] = String.valueOf(i);
    }

    for (int i =0; i<w;i++) {
    rows[i] = String.valueOf(i);//Rows
    }

    //Transformation matrice
    String[][] value2 = new String[w][6];
    int i =0;
    while(i<w){
    value2[i][5]= rows[i];
    i++;
    }

    JTable table = new JTable(value,col);
    JTableHeader header = table.getTableHeader();
    header.setBackground(Color.yellow);
    //JScrollPane pane = new JScrollPane(table);

    JTable rowHeader = new JTable(value2, col);
    rowHeader.setBackground(Color.yellow);

    JScrollPane pane = new JScrollPane();
    pane.setViewportView(table);
    pane.setRowHeaderView(rowHeader);

    rowHeader.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    panel.add(pane);
    frame.add(panel);
    frame.setSize(1000,500);
    frame.setUndecorated(true);
    frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);
    }
    }
    Ma matrice que j'ai est suivant regardé le lien suivant:
    http://forums.dcm4che.org/jiveforums...=3821&tstart=0

  4. #4
    Membre à l'essai
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    28
    Détails du profil
    Informations personnelles :
    Localisation : France, Indre et Loire (Centre)

    Informations forums :
    Inscription : Octobre 2009
    Messages : 28
    Points : 23
    Points
    23
    Par défaut
    J'ai résolu le problème en faisant deux tableaux, j'ai un tableau fixe.
    Mais je souhaite que le tableau fixe soit coller au tableau mobile.

    Voici mon code :
    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
     
     public  Table6(int value[][]){
      JFrame frame = new JFrame("Table Pixel");
      JPanel panel = new JPanel();
     
      int h = value.length;
      int w = value[0].length;
     
     
      String[] col = new String[h+1];
    String col1[] = new String[1]; 
      col1[0] =String.valueOf(""); 
     
        String[] rows = new String[w];
          String[] rows2 = new String[w];
     
       for (int i = 0; i<h; i++){
     
              col[0] =String.valueOf(""); 
         col[i+1] = String.valueOf(i);//columns
     
      }
     
      for (int i =0; i<w;i++) {
          rows[i] = String.valueOf(i);//Rows
      }
     
     
      for (int i =0; i<w;i++) {
          rows2[i] = String.valueOf(i);//Rows
      }
     
     
     
      //Transformation matrice
       String[][] value2 = new String[w][6];
       int i =0;
       while(i<w){
       value2[i][5]= rows[i];
         i++;
       }
     
       //Translate value
          String[][] value3 = new String[w+1][h+1];
          for (int x =0; x<h; x++){
        for (int y=0; y<w;y++){
            value3[x][y+1]= String.valueOf(value[x][y]);
            value3[x][0] = rows[x];
     
        }
          }
      String[][] value4 = new String[w+1][1];
         for (int x =0; x<w; x++){
     
                    value4[x][0] = rows2[x];
     
     
          }
     
     
     
             DefaultTableModel dtm = new DefaultTableModel(value3,col);
             JTable table=new JTable(dtm)
                 {
                 public Component prepareRenderer(TableCellRenderer renderer, int row, int column)
                     {
                     Component component = super.prepareRenderer(renderer,row,column);
     
                     if(column == 0)
                         {
                         component.setBackground(Color.yellow);
                     }
                    if(column !=0)
                         {
                         component.setBackground(Color.white);
                     }
                     return component;
                 }
             };
     
     
          DefaultTableModel dtm2 = new DefaultTableModel(value4,col1);
             JTable table5=new JTable(dtm2);
          table5.getColumnModel().getColumn(0).setMaxWidth(29);
      table5.setLocation(w,0 );
      table.getTableHeader().setReorderingAllowed(false);//lock colonne
      table.getTableHeader().setResizingAllowed(false);
      for(int r = 0; r<w+1; r++){
     table.getColumnModel().getColumn(r).setPreferredWidth(29);
      }
     
     
      JTableHeader header = table.getTableHeader();
      header.setBackground(Color.yellow);
     
         table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
          table5.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
         JScrollPane pane = new JScrollPane(panel);
            pane.setRowHeaderView( table5); 
            pane.setViewportView(table);
     
    frame.add(pane);
     // frame.add(panel);
      frame.setSize(500,500);
      frame.setUndecorated(true);
      frame.getRootPane().setWindowDecorationStyle(JRootPane.PLAIN_DIALOG);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);
     
         }
    Je vous joins la capture d'écran.
    Merci d'avance,
    Images attachées Images attachées  

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. mettre un checkbox dans une jtable
    Par christianf dans le forum Composants
    Réponses: 9
    Dernier message: 20/11/2010, 18h52
  2. [Etat]Mettre deux table dans un meme état?
    Par fafaf dans le forum IHM
    Réponses: 2
    Dernier message: 30/04/2007, 14h12
  3. [Formulaire] Mettre deux submit dans un formulaire
    Par sagitarium dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 02/11/2006, 20h24
  4. Comment mettre un JButton dans une JTable
    Par vinceLeBarbare dans le forum Composants
    Réponses: 6
    Dernier message: 05/06/2006, 11h43
  5. [c#] PDA mettre deux valeur dans le Displaymember du combobox
    Par FunkyB dans le forum Windows Forms
    Réponses: 2
    Dernier message: 27/04/2006, 13h57

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