Problem in editing JTable fields.....
Hi there!!
I have got 2 classes in my package,one contains a public static JTable while the other has got some variables whose values I want the JTable's fields to populate with.Now the problem I have is that I can't populate the JTable's fields after making it's class's object and accessing the JTable using that object...Can anybody help plz?
Thanks...
# 4
Hi Cantry!!
I'm embedding my code in this post,,had to simplify the code as my application's code may not have been understandable,,,
Here's the code
//THIS IS THE CLASS CONTAINING JTable
import java.sql.*;
import java.util.StringTokenizer;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.*;
public class Test_GUI extends javax.swing.JFrame {
/** Creates new form Test_GUI */
public Test_GUI() {
initComponents();
}
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("New Allocations");
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"
}
));
jScrollPane1.setViewportView(jTable1);
org.jdesktop.layout.GroupLayout layout = new
org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(57, 57, 57)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 344,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(106, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(55, 55, 55)
.add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 143,
org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addContainerGap(247, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
Test_GUI tg2=new Test_GUI();
tg2.SetTableValues();
/*
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Test_GUI().setVisible(true);
}
});
*/
try
{
javax.swing.UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}
catch(Exception e)
{
e.printStackTrace();
}
Test_GUI tg=new Test_GUI();
tg.setVisible(true);
}
// Variables declaration - do not modify
private javax.swing.JScrollPane jScrollPane1;
public static javax.swing.JTable jTable1;
// End of variables declaration
private javax.swing.JTextField jTextField6;
public static void SetTableValues()
{
System.out.println("here");
Data_Class dc=new Data_Class();
jTable1.setValueAt(dc.Test_data,0,0);
}
}
and code from the other calss,,,
//CLASS FROM WHERE I'M FETCHING THE DATA
public class Data_Class {
static String Test_data="testdata";
/** Creates a new instance of Data_Class */
public Data_Class() {
}
}
thanks in advance...