This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How can we create column headings with in JTable?  RSS feed

 
rameshmca rk
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to know details of setting column headings with data on JTable.I have given the program.Could you correct it to achieve the result?

import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.sql.*;
import java.util.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;
import com.sun.java.swing.plaf.windows.WindowsLookAndFeel;

public class Queresult extends JFrame
{
public Queresult()
{
//System.out.println("Welcome");

super(" Testing JTable ");
//Frame fm=new Frame();
JMenuBar bar=new JMenuBar();
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

JMenu m1=new JMenu("Master");
JMenu exit=new JMenu("Exit");

JMenuItem m1f1=new JMenuItem("JTable Form");
JMenuItem f6=new JMenuItem("Close");

m1.add(m1f1);
exit.add(f6);

bar.add(m1);
bar.add(exit);

setJMenuBar(bar);

f6.setForeground(Color.red);

setSize(800,570);
show();

addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);}});

m1f1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
Frame fm1=new Frame();form1 d=new form1(fm1);}});

f6.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
System.exit(0);}});

}
catch(Exception e)
{
e.printStackTrace();
}

}
public static void main(String args[])
{
new Queresult();
}
}

class form1 extends Dialog
{
JTable jt;
ResultSet rset=null;
Connection con=null;
Statement stmt=null;

form1(Frame fm1)
{
super(fm1);
setLayout(null);
setVisible(true);
Color c1=new Color(0,125,125);
setBackground(c1);
setSize(800,570);
setLocation(0,0);

final String[] colhead={"nou","uname"};
final Object[][] data={{"aaa","1234"},{"bbb","555"}};

jt=new JTable(data, colhead);
jt.setSize(200,100);
jt.setLocation(102,105);

add(jt);

}

}
 
Terry Ong
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try

add(new JScrollPane(jt));
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!