Results 1 to 12 of 12
  1. #1
    sagarvk is offline Member
    Join Date
    Jan 2015
    Posts
    25
    Rep Power
    0

    Default How to allow only decimal values in jtable?

    Hi How to restrict the input in a column of jtable to only decimal values and also format it to 2 decimal places.Pls help me in it.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: How to allow only decimal values in jtable?

    Best bet is to check the tutorials in my signature. They provide examples of how to set column and individual cell formats and types. Click on the big index and go to working with JTables.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    sagarvk is offline Member
    Join Date
    Jan 2015
    Posts
    25
    Rep Power
    0

    Default Re: How to allow only decimal values in jtable?

    I seen the tutorials but was unable to find the solution.Can you pls post a sample code and help me?

  4. #4
    sagarvk is offline Member
    Join Date
    Jan 2015
    Posts
    25
    Rep Power
    0

    Default Help needed for jtable

    Hi all
    I need help in validating the user input in jtable to accept only double values in col 1,3,4,5 in the code below.I am a newbie in java.I am using netbeans for the project Billing.Below is the code of the frame in netbeans. Pls help me.
    Java Code:
    package Billing;
    
    
    import com.sun.beans.editors.DoubleEditor;
    import java.awt.Component;
    import java.awt.event.KeyAdapter;
    import java.awt.event.KeyEvent;
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.text.NumberFormat;
    import net.proteanit.sql.DbUtils;
    import java.text.ParseException;
    import javax.swing.DefaultCellEditor;
    import javax.swing.JDesktopPane;
    import javax.swing.JFormattedTextField;
    import javax.swing.JInternalFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JTextField;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.text.MaskFormatter;
    
    
    
    /**
     *
     * @author Sai Ram
     */
    public class IBatchOpening extends javax.swing.JInternalFrame {
    Statement stmt;
    Connection conn;  
    ResultSet rs;
    PreparedStatement pstmt;
    public int INO;
    public String item;
    JTextField textBox=new JTextField();
    JFormattedTextField ftf;
    NumberFormat integerFormat;
    JFormattedTextField fd;
        public IBatchOpening() {
            initComponents();
            conn=DBConnect.Connect();
            lbliname.setText(item);
        try {
            stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null,ex.getMessage());
        }
        updatetable();
        Batch_Details.getColumnModel().getColumn(0).setHeaderValue("Batch No");
        Batch_Details.getColumnModel().getColumn(1).setHeaderValue("M.R.P");
        Batch_Details.getColumnModel().getColumn(2).setHeaderValue("Expiry Date");
        Batch_Details.getColumnModel().getColumn(3).setHeaderValue("Opng Stock");
        Batch_Details.getColumnModel().getColumn(4).setHeaderValue("Sales Rate");
        Batch_Details.getColumnModel().getColumn(5).setHeaderValue("Purch Rate");
        Batch_Details.getColumn("Batch No").setMinWidth(125);
        JOptionPane.showMessageDialog(null,INO);
        }
        private void updatetable(){
        try {
            String sql="select BATCH,MRP_RATE,EXP_DT,OP_QTY,SALE_RATE,PUR_RATE from BATCH where I_NO=?";
            pstmt=conn.prepareStatement(sql);
            pstmt.setInt(1, INO);
            rs=pstmt.executeQuery();
            Batch_Details.setModel(DbUtils.resultSetToTableModel(rs));
            
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null,ex.getMessage());
        }
            
        }
        /**
         * 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() {
    
            lbliname = new javax.swing.JLabel();
            jScrollPane1 = new javax.swing.JScrollPane();
            Batch_Details = new javax.swing.JTable();
            btnclose = new javax.swing.JButton();
            btnadd = new javax.swing.JButton();
            jLabel2 = new javax.swing.JLabel();
    
            setTitle("Batch-wise Opening Stock");
            addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
                public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
                }
                public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
                    formInternalFrameClosed(evt);
                }
                public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                }
                public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
                }
                public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
                }
                public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
                }
                public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                }
            });
    
            lbliname.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
            lbliname.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    
            Batch_Details.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                    {null, null, null, null, null, null, null},
                    {null, null, null, null, null, null, null},
                    {null, null, null, null, null, null, null},
                    {null, null, null, null, null, null, null}
                },
                new String [] {
                    "Title 1", "Title 2", "Title 3", "Title 4", "Title 5", "Title 6", "Title 7"
                }
            ) {
                Class[] types = new Class [] {
                    java.lang.Object.class, java.lang.Object.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class
                };
    
                public Class getColumnClass(int columnIndex) {
                    return types [columnIndex];
                }
            });
            Batch_Details.setRowHeight(20);
            Batch_Details.addKeyListener(new java.awt.event.KeyAdapter() {
                public void keyPressed(java.awt.event.KeyEvent evt) {
                    Batch_DetailsKeyPressed(evt);
                }
            });
            jScrollPane1.setViewportView(Batch_Details);
    
            btnclose.setText("Close");
            btnclose.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btncloseActionPerformed(evt);
                }
            });
    
            btnadd.setText("Add");
            btnadd.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btnaddActionPerformed(evt);
                }
            });
    
            jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
            jLabel2.setText("Batch-wise Opening Stock");
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 526, Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addComponent(btnadd, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(btnclose)))
                            .addContainerGap())
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGap(0, 0, Short.MAX_VALUE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lbliname, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(151, 151, 151))))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(lbliname, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(4, 4, 4)
                    .addComponent(jLabel2)
                    .addGap(18, 18, 18)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 44, Short.MAX_VALUE)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(btnadd)
                        .addComponent(btnclose))
                    .addContainerGap())
            );
    
            pack();
        }// </editor-fold>                        
    
        private void formInternalFrameClosed(javax.swing.event.InternalFrameEvent evt) {                                         
           
        }                                        
    
        private void btncloseActionPerformed(java.awt.event.ActionEvent evt) {                                         
    
        JDesktopPane desktopPane = getDesktopPane();
        JInternalFrame[] frames = desktopPane.getAllFrames();
        for (int i = 0 ; i < frames.length ; i ++)
        {
        frames[i].setVisible(true);
        }
        this.dispose();
        }                                        
    
        private void btnaddActionPerformed(java.awt.event.ActionEvent evt) {                                       
         DefaultTableModel model = (DefaultTableModel) Batch_Details.getModel();
         model.addRow(new Object[]{"","","","","",""}); {
                Class[] types = new Class [] {
                    java.lang.Object.class, java.lang.Object.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class
                };
            }
        JFormattedTextField ftext = new JFormattedTextField();
       MaskFormatter mask;
       try {
        mask = new MaskFormatter("##/##/####");
        mask.install(ftext);
       } catch (ParseException e) {
        e.printStackTrace();
      }
    
        
        Batch_Details.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(ftext));
        
        
        
        }                                      
    
     
        private void Batch_DetailsKeyPressed(java.awt.event.KeyEvent evt) {                                         
        
        }                                        
    
        // Variables declaration - do not modify                     
        private javax.swing.JTable Batch_Details;
        private javax.swing.JButton btnadd;
        private javax.swing.JButton btnclose;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JLabel lbliname;
        // End of variables declaration                   
    }

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: How to allow only decimal values in jtable?

    Don't start a new thread for the same question. I've merged th two threads here.

    Also moved the thread from New to Java to AWT/Swing.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    sagarvk is offline Member
    Join Date
    Jan 2015
    Posts
    25
    Rep Power
    0

    Default Re: How to allow only decimal values in jtable?

    I used the following code and it worked for me.Thanks to all for posting your replys.
    Java Code:
    DecimalFormat dfpr = new DecimalFormat("######0.00");
    NumberFormatter formatterpr = new NumberFormatter(dfpr);
    formatterpr.setAllowsInvalid(false);
    JFormattedTextField PR = new JFormattedTextField(formatterpr);
    PR.setBorder(null);
    Batch_Details.getColumnModel().getColumn(5).setCellEditor(new DefaultCellEditor(PR));

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: How to allow only decimal values in jtable?

    Quote Originally Posted by sagarvk View Post
    I used the following code and it worked for me.Thanks to all for posting your replys.
    Your question was about JTables and column formats. I think you omitted an important detail about your environment. That syntax looks very strange and won't compile (unless there is some preprocessor involved).

    Regards,
    Jim
    Last edited by jim829; 02-01-2015 at 07:10 PM.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  8. #8
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: How to allow only decimal values in jtable?

    Quote Originally Posted by jim829 View Post
    That syntax looks very strange and won't compile (unless there is some preprocessor involved).
    The <acronym...> tags appear to be an artifact of the forum software.

    Test: without code tags - pr
    In code tags
    Java Code:
    pr
    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: How to allow only decimal values in jtable?

    Note the autolink in the above post. Now lets see what happen in uppercase: PR
    Java Code:
    PR
    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  10. #10
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: How to allow only decimal values in jtable?

    Ha!

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  11. #11
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: How to allow only decimal values in jtable?

    Quote Originally Posted by DarrylBurke View Post
    The tags appear to be an artifact of the forum software.
    Well that explains it! That never occurred to me.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  12. #12
    sagarvk is offline Member
    Join Date
    Jan 2015
    Posts
    25
    Rep Power
    0

    Default Re: How to allow only decimal values in jtable?

    Here is the full code of the jinternalframe which contains jtable.
    Java Code:
    package Billing;
    
    
    
    import java.sql.Connection;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.text.DecimalFormat;
    import net.proteanit.sql.DbUtils;
    import java.text.ParseException;
    import javax.swing.DefaultCellEditor;
    import javax.swing.JDesktopPane;
    import javax.swing.JFormattedTextField;
    import javax.swing.JInternalFrame;
    import javax.swing.JOptionPane;
    import javax.swing.table.DefaultTableModel;
    import javax.swing.text.MaskFormatter;
    import javax.swing.text.NumberFormatter;
    
    
    /**
     *
     * @author Sai Ram
     */
    public class IBatchOpening extends javax.swing.JInternalFrame {
    Statement stmt;
    Connection conn;  
    ResultSet rs;
    PreparedStatement pstmt;
    public int INO=Itemmaster.INO();
        public IBatchOpening() {
            initComponents();
            conn=DBConnect.Connect();
            
            
        try {
            stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null,ex.getMessage());
        }
        updatetable();
        Batch_Details.getColumnModel().getColumn(0).setHeaderValue("Batch No");
        Batch_Details.getColumnModel().getColumn(1).setHeaderValue("M.R.P");
        Batch_Details.getColumnModel().getColumn(2).setHeaderValue("Expiry Date");
        Batch_Details.getColumnModel().getColumn(3).setHeaderValue("Opng Stock");
        Batch_Details.getColumnModel().getColumn(4).setHeaderValue("Sales Rate");
        Batch_Details.getColumnModel().getColumn(5).setHeaderValue("Purch Rate");
        Batch_Details.getColumn("Batch No").setMinWidth(125);
        
        }
        private void updatetable(){
        try {
            String sql="select BATCH,MRP_RATE,EXP_DT,OP_QTY,SALE_RATE,PUR_RATE from BATCH where I_NO=?";
            pstmt=conn.prepareStatement(sql);
            pstmt.setInt(1, INO);
            rs=pstmt.executeQuery();
            Batch_Details.setModel(DbUtils.resultSetToTableModel(rs));
            
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null,ex.getMessage());
        }
        
        }
        /**
         * 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() {
    
            lbliname = new javax.swing.JLabel();
            jScrollPane1 = new javax.swing.JScrollPane();
            Batch_Details = new javax.swing.JTable();
            btnclose = new javax.swing.JButton();
            btnadd = new javax.swing.JButton();
            jLabel2 = new javax.swing.JLabel();
    
            setTitle("Batch-wise Opening Stock");
            addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
                public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
                }
                public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
                    formInternalFrameClosed(evt);
                }
                public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
                }
                public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
                }
                public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
                }
                public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
                }
                public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
                }
            });
    
            lbliname.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
            lbliname.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
    
            Batch_Details.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                    {null, null, null, null, null, null, null},
                    {null, null, null, null, null, null, null},
                    {null, null, null, null, null, null, null},
                    {null, null, null, null, null, null, null}
                },
                new String [] {
                    "Title 1", "Title 2", "Title 3", "Title 4", "Title 5", "Title 6", "Title 7"
                }
            ) {
                Class[] types = new Class [] {
                    java.lang.Object.class, java.lang.Object.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class, java.lang.Double.class
                };
    
                public Class getColumnClass(int columnIndex) {
                    return types [columnIndex];
                }
            });
            Batch_Details.setRowHeight(20);
            Batch_Details.addKeyListener(new java.awt.event.KeyAdapter() {
                public void keyPressed(java.awt.event.KeyEvent evt) {
                    Batch_DetailsKeyPressed(evt);
                }
            });
            jScrollPane1.setViewportView(Batch_Details);
    
            btnclose.setText("Close");
            btnclose.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btncloseActionPerformed(evt);
                }
            });
    
            btnadd.setText("Add");
            btnadd.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    btnaddActionPerformed(evt);
                }
            });
    
            jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
            jLabel2.setText("Batch-wise Opening Stock");
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 526, Short.MAX_VALUE)
                                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                                    .addComponent(btnadd, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(btnclose)))
                            .addContainerGap())
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGap(0, 0, Short.MAX_VALUE)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(lbliname, javax.swing.GroupLayout.PREFERRED_SIZE, 242, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(151, 151, 151))))
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(lbliname, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(btnadd)
                        .addComponent(btnclose))
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
    
            pack();
        }// </editor-fold>                        
    
        private void formInternalFrameClosed(javax.swing.event.InternalFrameEvent evt) {                                         
           
        }                                        
    
        private void btncloseActionPerformed(java.awt.event.ActionEvent evt) {                                         
    
        JDesktopPane desktopPane = getDesktopPane();
        JInternalFrame[] frames = desktopPane.getAllFrames();
        for (int i = 0 ; i < frames.length ; i ++)
        {
        frames[i].setVisible(true);
        }
        this.dispose();
        }                                        
    
        private void btnaddActionPerformed(java.awt.event.ActionEvent evt) {                                       
         DefaultTableModel model = (DefaultTableModel) Batch_Details.getModel();
         
         model.addRow(new Object[]{"","","","","",""}); 
        JFormattedTextField dt = new JFormattedTextField();
        MaskFormatter mask;
        try {
        mask = new MaskFormatter("##/##/####");
        mask.install(dt);
       } catch (ParseException e) {
        e.printStackTrace();
      }
       
       DecimalFormat dfmrp = new DecimalFormat("######0.00");
       NumberFormatter formattermrp = new NumberFormatter(dfmrp);
       formattermrp.setAllowsInvalid(false);
       JFormattedTextField MRP = new JFormattedTextField(formattermrp);
       
       DecimalFormat dfop = new DecimalFormat("######0.00");
       NumberFormatter formatterop = new NumberFormatter(dfop);
       formatterop.setAllowsInvalid(false);
       JFormattedTextField OP = new JFormattedTextField(formatterop);
       
       DecimalFormat dfsr = new DecimalFormat("######0.00");
       NumberFormatter formattersr = new NumberFormatter(dfsr);
       formattersr.setAllowsInvalid(false);
       JFormattedTextField SR = new JFormattedTextField(formattersr);
       
       DecimalFormat dfpr = new DecimalFormat("######0.00");
       NumberFormatter formatterpr = new NumberFormatter(dfpr);
       formatterpr.setAllowsInvalid(false);
       JFormattedTextField PR = new JFormattedTextField(formatterpr);
       
       dt.setBorder(null);
       MRP.setBorder(null);
       OP.setBorder(null);
       SR.setBorder(null);
       PR.setBorder(null);
       
        Batch_Details.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(MRP));
        Batch_Details.getColumnModel().getColumn(2).setCellEditor(new DefaultCellEditor(dt));
        Batch_Details.getColumnModel().getColumn(3).setCellEditor(new DefaultCellEditor(OP));
        Batch_Details.getColumnModel().getColumn(4).setCellEditor(new DefaultCellEditor(SR));
        Batch_Details.getColumnModel().getColumn(5).setCellEditor(new DefaultCellEditor(PR));
        
        
        
        }                                      
    
     
        private void Batch_DetailsKeyPressed(java.awt.event.KeyEvent evt) {                                         
        
        }                                        
    
        // Variables declaration - do not modify                     
        private javax.swing.JTable Batch_Details;
        private javax.swing.JButton btnadd;
        private javax.swing.JButton btnclose;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JScrollPane jScrollPane1;
        public static javax.swing.JLabel lbliname;
        // End of variables declaration                   
    }

Similar Threads

  1. Replies: 1
    Last Post: 02-05-2014, 02:04 AM
  2. Replies: 4
    Last Post: 01-30-2010, 04:49 PM
  3. values in jtable
    By blackpearlmoni in forum AWT / Swing
    Replies: 4
    Last Post: 11-04-2009, 07:48 PM
  4. i want to display decimal values in frame window
    By santhosh_el in forum AWT / Swing
    Replies: 4
    Last Post: 03-16-2009, 09:07 AM
  5. Getting integer values from a JTable
    By zikojam in forum New To Java
    Replies: 1
    Last Post: 12-11-2008, 02:06 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •