Tuesday, December 24, 2013

java JTable resize Table Column

 try {
           
      
            //get table model
            DefaultTableModel model = (DefaultTableModel) jTable_sales_cotation.getModel();
            model.addRow(new Object[]{
                item_code, item_description, quantity, unit, price,
                discount, line_total });
               jTable_sales_cotation.setAutoResizeMode(jTable_sales_cotation.AUTO_RESIZE_OFF);
              jTable_sales_cotation.getColumnModel().getColumn(0).setPreferredWidth(70);
              jTable_sales_cotation.getColumnModel().getColumn(1).setPreferredWidth(270);
              jTable_sales_cotation.getColumnModel().getColumn(2).setPreferredWidth(50);
              jTable_sales_cotation.getColumnModel().getColumn(3).setPreferredWidth(52);
              jTable_sales_cotation.getColumnModel().getColumn(4).setPreferredWidth(110);
              jTable_sales_cotation.getColumnModel().getColumn(5).setPreferredWidth(78);
              jTable_sales_cotation.getColumnModel().getColumn(6).setPreferredWidth(90);
   
            //DB operation

            //log.main(query);
        } catch (Exception e) {
            JOptionPane.showMessageDialog(this, "Error: " + e, "Error in connectivity", JOptionPane.ERROR_MESSAGE);
        }
        update_total();
//        __Update_table();
//        __clear();

No comments:

Post a Comment