
Sir, I created one JTable with two columns and one row i have given two values,but i getting only one value .That is a[1][1] is String array. if i have given 8,9 then i got 8 only but not 9.i.e a[0][0]=8 a[0][1]= (nothing printed) Please go through my code
import java.util.*; import java.awt.*;
import javax.swing.*; import javax.swing.event.*; import java.awt.event.*; import java.awt.print.*; import java.sql.*; public class sd25 extends JFrame implements ActionListener { //3 month table details JTable table=null; JScrollPane js=null; Container cp=null; JPanel p=null; JLabel months3=null,date=null,ghba1c=null,per=null; JButton jb1=null; String a[][]=new String[2][2]; Connection con=null; Statement stmt=null; ResultSet rs=null; public sd25()throws Exception { cp=getContentPane(); cp.setLayout(null); cp.setBackground(Color.pink);
//3monts details months3=new JLabel("3 Months-Report"); date=new JLabel("Date"); ghba1c=new JLabel("GHbA1c"); per=new JLabel("%");
//3 monts details
final Object colheads[]={"Date","%"}; final Object rowdata[][]={{"",""},{"",""}}; table=new JTable(rowdata,colheads); p=new JPanel(null); months3.setBounds(40,10,300,40); date.setBounds(190,20,300,40); ghba1c.setBounds(400,20,300,40); per.setBounds(470,20,300,40); table.setBounds(100,50,460,15); jb1=new JButton("submit"); jb1.setBounds(790,400,100,40); int h=ScrollPaneConstants.HORIZONTALSCROLLBARAS_NEEDED; int v=ScrollPaneConstants.VERTICALSCROLLBARAS_NEEDED;
jb1.addActionListener(this); cp.add(per); cp.add(ghba1c); cp.add(date); cp.add(months3); cp.add(table); cp.add(jb1);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
dispose();
//System.exit(0);
}
});
}
public void actionPerformed(ActionEvent ae)
{
System.out.println("hi");
if(ae.getSource()==jb1)
{
try
{
for(int i=0;i<1;i++)
{
for(int j=0;j<=1;j++)
{
a[i][j]=(String)table.getModel().getValueAt(i,j); } }
for(int i=0;i<1;i++) { for(int j=0;j<=1;j++) { System.out.println("\n"+i+""+j+""+a[i][j]); } }
cp.setBackground(Color.red);
}catch(Exception e)
{
e.printStackTrace();
}
}
}
public static void main(String args[])throws Exception
{
sd25 o=new sd25();
o.setSize(900,900);
o.show();
} }
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.