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

NetBeans Java Discussion :

Cacher la première colonne dans une Jtable


Sujet :

NetBeans Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    200
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2006
    Messages : 200
    Par défaut Cacher la première colonne dans une Jtable
    Bonjour,

    J'ai suivi une reponse donnée sur le forum, mais ça ne fonctionne toujours pas pour mon application.
    J'utilise netbeans 7 et j'aimerai cacher une colonne dans ma Jtable, plus exactement le ID de l'employee, car l'utilisateur n'a pas besoin de voir l'information, mais par contre moi, je dois l'utiliser pour faire des sql basés sur cette information.
    malgré que j'ai forcé la largeur de la colonne a 0, la colonne est toujours visible a l'execution de la class.
    voir bout de code:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     public QMSHR() {
     
            initComponents();
     
            //employeeList.removeColumn(employeeList.getColumnModel().getColumn(0));
     
            employeeList.getColumn("ID").setWidth(0);
            employeeList.getColumn("ID").setMaxWidth(0);
            employeeList.getColumn("ID").setMinWidth(0);
     
            employeeTable();
        }
    voici mon code au complet :
    le nom de la table est employeeList
    merci de votre aide.

    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
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
     
    package qmshr;
     
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import javax.swing.table.DefaultTableModel;
     
    public class QMSHR extends javax.swing.JFrame {
     
        public Object header[] = {"ID","First Name ","Last Name ","Project"};
        public Object data[][] = {};
        public DefaultTableModel model = new DefaultTableModel(data,header);
        public Connection con = null;
        public ResultSet rs = null;
        public Statement st = null;
     
     
        /**
         * Creates new form QMSHR
         */
        public QMSHR() {
     
            initComponents();
     
            //employeeList.removeColumn(employeeList.getColumnModel().getColumn(0));
     
            employeeList.getColumn("ID").setWidth(0);
            employeeList.getColumn("ID").setMaxWidth(0);
            employeeList.getColumn("ID").setMinWidth(0);
     
            employeeTable();
        }
     
        /**
         * This method is called from within the constructor to initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is always
         * regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">
        private void initComponents() {
     
            jMenu3 = new javax.swing.JMenu();
            jScrollPane1 = new javax.swing.JScrollPane();
            employeeList = new javax.swing.JTable();
            jButtonExit = new javax.swing.JButton();
            jLemployeeName = new javax.swing.JLabel();
            jPanelEmp = new javax.swing.JPanel();
            jTemployeeCode = new javax.swing.JTextField();
            jLabelEmpId = new javax.swing.JLabel();
            jTfirstName = new javax.swing.JTextField();
            jLabelEmpId1 = new javax.swing.JLabel();
            jLabelEmpId2 = new javax.swing.JLabel();
            jTlastName = new javax.swing.JTextField();
            jButton1 = new javax.swing.JButton();
            jLabel9 = new javax.swing.JLabel();
            jLabel12 = new javax.swing.JLabel();
            jMenuBar = new javax.swing.JMenuBar();
            jMenuHome = new javax.swing.JMenu();
            jMenuLng = new javax.swing.JMenu();
            jMenu1 = new javax.swing.JMenu();
            jMenu2 = new javax.swing.JMenu();
            jMenu4 = new javax.swing.JMenu();
            jMenu5 = new javax.swing.JMenu();
            jMenu6 = new javax.swing.JMenu();
     
            jMenu3.setText("jMenu3");
     
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("QMS HR");
     
            employeeList.setAutoCreateRowSorter(true);
            employeeList.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
            employeeList.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                    {null, null, null, null}
                },
                new String [] {
                    "ID", "Title 2", "Title 3", "Title 4"
                }
            ) {
                boolean[] canEdit = new boolean [] {
                    false, true, true, true
                };
     
                public boolean isCellEditable(int rowIndex, int columnIndex) {
                    return canEdit [columnIndex];
                }
            });
            employeeList.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mousePressed(java.awt.event.MouseEvent evt) {
                    employeeListMousePressed(evt);
                }
            });
            jScrollPane1.setViewportView(employeeList);
            employeeList.getColumnModel().getColumn(0).setResizable(false);
            employeeList.getColumnModel().getColumn(0).setPreferredWidth(0);
     
            jButtonExit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/exit.jpg"))); // NOI18N
            jButtonExit.setToolTipText("");
            jButtonExit.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/images/button2exit.gif"))); // NOI18N
     
            jLemployeeName.setFont(new java.awt.Font("Times New Roman", 0, 24)); // NOI18N
            jLemployeeName.setForeground(new java.awt.Color(0, 51, 255));
            jLemployeeName.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/2502.png"))); // NOI18N
            jLemployeeName.setName("jLemployeeName");
     
            jPanelEmp.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "-Employee-", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Times New Roman", 0, 14), java.awt.Color.white)); // NOI18N
     
            jTemployeeCode.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
     
            jLabelEmpId.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
            jLabelEmpId.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
            jLabelEmpId.setText("Employee Code");
     
            jTfirstName.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
            jTfirstName.addFocusListener(new java.awt.event.FocusAdapter() {
                public void focusLost(java.awt.event.FocusEvent evt) {
                    jTfirstNameFocusLost(evt);
                }
            });
     
            jLabelEmpId1.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
            jLabelEmpId1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
            jLabelEmpId1.setText("First Name");
     
            jLabelEmpId2.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
            jLabelEmpId2.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
            jLabelEmpId2.setText("Last Name");
     
            jTlastName.setFont(new java.awt.Font("Times New Roman", 0, 14)); // NOI18N
            jTlastName.addFocusListener(new java.awt.event.FocusAdapter() {
                public void focusLost(java.awt.event.FocusEvent evt) {
                    jTlastNameFocusLost(evt);
                }
            });
     
            jButton1.setFont(new java.awt.Font("Times New Roman", 1, 13)); // NOI18N
            jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/accmdsave.jpg"))); // NOI18N
            jButton1.setRolloverIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon_disk.png"))); // NOI18N
     
            javax.swing.GroupLayout jPanelEmpLayout = new javax.swing.GroupLayout(jPanelEmp);
            jPanelEmp.setLayout(jPanelEmpLayout);
            jPanelEmpLayout.setHorizontalGroup(
                jPanelEmpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelEmpLayout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(jPanelEmpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabelEmpId, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jTemployeeCode, javax.swing.GroupLayout.PREFERRED_SIZE, 92, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGap(42, 42, 42)
                    .addGroup(jPanelEmpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabelEmpId1, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanelEmpLayout.createSequentialGroup()
                            .addGap(1, 1, 1)
                            .addComponent(jTfirstName, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGap(28, 28, 28)
                    .addGroup(jPanelEmpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabelEmpId2, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGroup(jPanelEmpLayout.createSequentialGroup()
                            .addGap(1, 1, 1)
                            .addComponent(jTlastName, javax.swing.GroupLayout.PREFERRED_SIZE, 153, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                            .addComponent(jButton1)))
                    .addContainerGap())
            );
            jPanelEmpLayout.setVerticalGroup(
                jPanelEmpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanelEmpLayout.createSequentialGroup()
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanelEmpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanelEmpLayout.createSequentialGroup()
                            .addComponent(jLabelEmpId1)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jTfirstName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanelEmpLayout.createSequentialGroup()
                            .addComponent(jLabelEmpId)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jTemployeeCode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanelEmpLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanelEmpLayout.createSequentialGroup()
                                .addComponent(jLabelEmpId2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTlastName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
            );
     
            jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Q_logo.gif"))); // NOI18N
            jLabel9.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
     
            jLabel12.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/Q_Line.gif"))); // NOI18N
     
            jMenuBar.setFont(new java.awt.Font("Times New Roman", 1, 14)); // NOI18N
     
            jMenuHome.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon_homepage.png"))); // NOI18N
            jMenuHome.setText("Home");
            jMenuBar.add(jMenuHome);
     
            jMenuLng.setText("Language");
            jMenuBar.add(jMenuLng);
     
            jMenu1.setText("jMenu1");
            jMenuBar.add(jMenu1);
     
            jMenu2.setText("jMenu2");
            jMenuBar.add(jMenu2);
     
            jMenu4.setText("jMenu4");
            jMenuBar.add(jMenu4);
     
            jMenu5.setText("jMenu5");
            jMenuBar.add(jMenu5);
     
            jMenu6.setText("Help");
            jMenuBar.add(jMenu6);
     
            setJMenuBar(jMenuBar);
     
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(10, 10, 10)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 378, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLemployeeName, javax.swing.GroupLayout.PREFERRED_SIZE, 354, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(18, 18, 18)
                                    .addComponent(jPanelEmp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jButtonExit, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGroup(layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jLabel9)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 596, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(12, 12, 12)))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 73, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 551, Short.MAX_VALUE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jLemployeeName, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jPanelEmp, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jButtonExit))))
            );
     
            pack();
        }// </editor-fold>
     
        private void employeeListMousePressed(java.awt.event.MouseEvent evt) {                                          
            int selectedRow = employeeList.getSelectedRow();
            String selectedName = employeeList.getValueAt(selectedRow, 1) + ", " + employeeList.getValueAt(selectedRow, 2);
            jLemployeeName.setText(selectedName);
        }                                         
     
        private void jTfirstNameFocusLost(java.awt.event.FocusEvent evt) {                                      
            jTfirstName.setText(capitalizeFirst(jTfirstName.getText()));
        }                                     
     
        private void jTlastNameFocusLost(java.awt.event.FocusEvent evt) {                                     
            jTlastName.setText(capitalizeFirst(jTlastName.getText()));
        }                                    
     
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            /*
             * Set the Nimbus look and feel
             */
            //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
            /*
             * If Nimbus (introduced in Java SE 6) is not available, stay with the
             * default look and feel. For details see
             * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
             */
            try {
                for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                    if ("Nimbus".equals(info.getName())) {
                        javax.swing.UIManager.setLookAndFeel(info.getClassName());
                        break;
                    }
                }
            } catch (ClassNotFoundException ex) {
                java.util.logging.Logger.getLogger(QMSHR.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (InstantiationException ex) {
                java.util.logging.Logger.getLogger(QMSHR.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (IllegalAccessException ex) {
                java.util.logging.Logger.getLogger(QMSHR.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            } catch (javax.swing.UnsupportedLookAndFeelException ex) {
                java.util.logging.Logger.getLogger(QMSHR.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
            }
            //</editor-fold>
     
            /*
             * Create and display the form
             */
            java.awt.EventQueue.invokeLater(new Runnable() {
     
                public void run() {
     
                    QMSHR qm = new QMSHR();
                    qm.setLocationRelativeTo(null);
                    new QMSHR().setVisible(true);
     
                }
            });
        }
     
     
        private void employeeTable(){
            con = Connect.ConnectDB();
            String sql = "Select ID, FirstName, LastName, Currentproject " 
                    + "FROM Employees INNER JOIN [Agt Info Sheet 1] ON Employees.ID = [Agt Info Sheet 1].IDempl "
                    + "WHERE ((([Agt Info Sheet 1].DepartDate) Is Null)) "
                + " ORDER BY Employees.FirstName; ";
            try{
     
                st = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
                rs = st.executeQuery(sql);
     
                rs.last();
                int row = rs.getRow();              
     
                rs.first();
              //  System.out.println("=======" + rs.getString("ID"));
                data = new Object[row][4];
                int i = 0;
                while (rs.next()){
                        data[i][0] = rs.getString("ID");
                        data[i][1] = rs.getString("FirstName");
                        data[i][2] = rs.getString("LastName");
                        data[i][3] = rs.getString("Currentproject");
                        i = i + 1;
     
                }
                employeeList.setModel(new DefaultTableModel(data,header));
            }catch(Exception ex){
                System.out.println("error:" + ex.getMessage());
            }  
     
     
    }    
        private String capitalizeFirst(String s){ 
            if (s.length() == 0) return s;
            return s.substring(0, 1).toUpperCase() + s.substring(1).toLowerCase();
     
          //  return s;
        }
     
        // Variables declaration - do not modify
        private volatile javax.swing.JTable employeeList;
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButtonExit;
        private javax.swing.JLabel jLabel12;
        private javax.swing.JLabel jLabel9;
        private javax.swing.JLabel jLabelEmpId;
        private javax.swing.JLabel jLabelEmpId1;
        private javax.swing.JLabel jLabelEmpId2;
        private javax.swing.JLabel jLemployeeName;
        private javax.swing.JMenu jMenu1;
        private javax.swing.JMenu jMenu2;
        private javax.swing.JMenu jMenu3;
        private javax.swing.JMenu jMenu4;
        private javax.swing.JMenu jMenu5;
        private javax.swing.JMenu jMenu6;
        private javax.swing.JMenuBar jMenuBar;
        private javax.swing.JMenu jMenuHome;
        private javax.swing.JMenu jMenuLng;
        private javax.swing.JPanel jPanelEmp;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTextField jTemployeeCode;
        private javax.swing.JTextField jTfirstName;
        private javax.swing.JTextField jTlastName;
        // End of variables declaration
    }

  2. #2
    Membre émérite Avatar de fraco
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    750
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Juin 2006
    Messages : 750
    Par défaut
    Salut !

    comme ça ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
       jXTable1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
       JTableHeader header = jXTable1.getTableHeader();
       TableColumn column =  jXTable1.getColumnModel().getColumn(1);
       header.setResizingColumn(column);                  // this line is very important
       column.setMinWidth(0);                       // permettre une largeur zéro
       column.setWidth(0);                 //  cacher la colonne un

  3. #3
    Membre Expert
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 276
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 276
    Par défaut
    Une solution plus propre serait de passer par un TableModel maison dans lequel tu n'affiches pas ton id.

  4. #4
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    200
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2006
    Messages : 200
    Par défaut
    Merci fraco pour ta réponse,
    J'ai ajouté le code, mais la premiere colonne est toujours presente. par contre maintenant les 4 colonnes sont positionnées a la meme largeur.
    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
     public QMSHR() {
     
            initComponents();
     
            employeeList.setAutoResizeMode(employeeList.AUTO_RESIZE_OFF); 
            JTableHeader header = employeeList.getTableHeader();
            TableColumn column = employeeList.getColumnModel().getColumn(1);
            header.setResizingColumn(column);   
            column.setMinWidth(0);                       
            column.setMaxWidth(0); 
            column.setWidth(0); 
     
            employeeTable();
        }

  5. #5
    Membre confirmé
    Profil pro
    Inscrit en
    Septembre 2006
    Messages
    200
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Septembre 2006
    Messages : 200
    Par défaut
    En attendant la reponse de la part de fraco,
    fr1man as tu un exemple que je peux suivre?
    merci

  6. #6
    Modérateur
    Avatar de dinobogan
    Homme Profil pro
    ingénieur
    Inscrit en
    Juin 2007
    Messages
    4 073
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France

    Informations professionnelles :
    Activité : ingénieur
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 4 073
    Par défaut
    La solution de fr1man est la plus propre. Il s'agit d'utiliser soit ton propre TableModel en redéfinissant les méthodes pour le nombre de colonnes, le nom et les valeurs des cellules, soit utiliser le pattern Decorator si tu as déjà ton propre TableModel.

    Tu trouveras toute la documentation nécessaire sur le site pour créer ton propre TableModel.
    N'oubliez pas de consulter les FAQ Java et les cours et tutoriels Java
    Que la force de la puissance soit avec le courage de ta sagesse.

  7. #7
    Membre émérite Avatar de fraco
    Profil pro
    Inscrit en
    Juin 2006
    Messages
    750
    Détails du profil
    Informations personnelles :
    Localisation : Suisse

    Informations forums :
    Inscription : Juin 2006
    Messages : 750
    Par défaut
    Salut !

    Je crois qu'il faut mettre ce code après la méthode employeeTable();
    Mais c'est vrai que c'est mieux de passer par le modéle.....

    Bonne chance !

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

Discussions similaires

  1. Rendre une Colonne dans une JTable invisible
    Par Soulama dans le forum Composants
    Réponses: 8
    Dernier message: 20/02/2011, 12h28
  2. [C++ 6.0] : Cacher une colonne dans une liste
    Par Mirna dans le forum MFC
    Réponses: 1
    Dernier message: 08/02/2007, 19h31
  3. Dimension d'une colonne dans un JTable
    Par hbzied dans le forum Composants
    Réponses: 1
    Dernier message: 16/05/2006, 21h01
  4. des combos differentes dans une meme colonne d'une Jtable
    Par mickael.guilbert dans le forum Composants
    Réponses: 2
    Dernier message: 13/05/2006, 11h31
  5. Icon pour pour JButton dans une Jtable + pb colonnes
    Par dim_italia dans le forum Composants
    Réponses: 3
    Dernier message: 22/02/2006, 18h05

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