Skip to main content

Jtable numeric validation for JOptionpane

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
No replies
jprofessiona
Offline
Joined: 2011-08-22

Hi i am newbie to swing. Please guide , how can i popup JOptionPane message('Pls enter numeric value') for non-numeric value in JTable (colum 1 & column 3) instead default bolder highlight red .

//here the code:

public class Frame6 extends javax.swing.JFrame {

public Frame6() {

initComponents();

}

private void initComponents() {

jScrollPane1 = new javax.swing.JScrollPane();

jTable1 = new javax.swing.JTable();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

setName("Form");

jScrollPane1.setName("jScrollPane1");

jTable1.setModel(new javax.swing.table.DefaultTableModel(

new Object [][] {

{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"

}

) {

Class[] types = new Class [] {

java.lang.Object.class, java.lang.Integer.class, java.lang.Object.class, java.lang.Integer.class

};

public Class getColumnClass(int columnIndex) {

return types [columnIndex];

}

});

jTable1.setName("jTable1"); // NOI18N

jScrollPane1.setViewportView(jTable1);

org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(jtabledemo.JTableDemoApp.class).getContext().getResourceMap(Frame6.class);

jTable1.getColumnModel().getColumn(0).setResizable(false);

jTable1.getColumnModel().getColumn(0).setHeaderValue(resourceMap.getString("jTable1.columnModel.title0")); // NOI18N

jTable1.getColumnModel().getColumn(1).setResizable(false);

jTable1.getColumnModel().getColumn(1).setHeaderValue(resourceMap.getString("jTable1.columnModel.title1")); // NOI18N

jTable1.getColumnModel().getColumn(2).setResizable(false);

jTable1.getColumnModel().getColumn(2).setHeaderValue(resourceMap.getString("jTable1.columnModel.title2")); // NOI18N

jTable1.getColumnModel().getColumn(3).setResizable(false);

jTable1.getColumnModel().getColumn(3).setHeaderValue(resourceMap.getString("jTable1.columnModel.title3")); // NOI18N

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());

getContentPane().setLayout(layout);

layout.setHorizontalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()

.addContainerGap(15, Short.MAX_VALUE)

.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 375, javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap())

);

layout.setVerticalGroup(

layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)

.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()

.addContainerGap(14, Short.MAX_VALUE)

.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE)

.addContainerGap())

);

pack();

}

public static void main(String args[]) {

java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {

new Frame6().setVisible(true);

}

});

}

private javax.swing.JScrollPane jScrollPane1;

private javax.swing.JTable jTable1;

}