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 :

comment fixer une colonne dans un Jtable


Sujet :

Composants Java

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    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
    Par défaut comment fixer une colonne dans un Jtable
    Je recherche le moyen de fixer dans mon JTable de pixel la colonne en jaune pour avec le JScrollPane que je peux déplacer.
    J'ai mis en pièce jointe ma capture de mon tableau que j'ai.

    Voici le code que je fais:

    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
     
    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(, col1);
              DefaultTableModel dtm2 = new DefaultTableModel(value4,col1);
                      JTable table2 = new JTable(dtm2){
                 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;
                 }
             }; 
     
     
     
      JTableHeader header2 = table2.getTableHeader();
      header2.setBackground(Color.yellow);
        table2.getColumn("").setPreferredWidth(50);
      table2.getTableHeader().setReorderingAllowed(false);//lock colonne
      table2.getTableHeader().setResizingAllowed(false);       
     
      table.getTableHeader().setReorderingAllowed(false);//lock colonne
      table.getTableHeader().setResizingAllowed(false);
     
      JTableHeader header = table.getTableHeader();
      header.setBackground(Color.yellow);
      JScrollPane pane = new JScrollPane();
      pane.setViewportView(table);
     
     
     
      table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
     
      panel.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);
     
         }
    Merci d'avance de vos aides,
    Images attachées Images attachées  

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

Discussions similaires

  1. Réponses: 0
    Dernier message: 13/04/2012, 17h57
  2. Dimension d'une colonne dans un JTable
    Par hbzied dans le forum Composants
    Réponses: 1
    Dernier message: 16/05/2006, 21h01
  3. Comment griser une ligne dans un JTable
    Par bpy1401 dans le forum Composants
    Réponses: 3
    Dernier message: 26/04/2006, 08h05
  4. Comment modifier une cellule dans un JTable
    Par @yoyo dans le forum Composants
    Réponses: 10
    Dernier message: 22/03/2006, 16h48
  5. Comment fixer une date dans un champ !
    Par LATHIOS dans le forum Access
    Réponses: 8
    Dernier message: 17/06/2005, 19h44

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