Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable  RSS feed

 
vesrak raju
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import java.awt.*;
import javax.swing.*;
public class JTable extends JFrame
{
public void init()
{
Container c=getContentPane();
c.setLayout(new BorderLayout());
c.setBackground(Color.yellow);
c.setForeground(Color.green);
c.setFont(new Font("Font.sans-serif", Font.PLAIN, 30));

String colHd[] = {"name", "qualification", "course"};
String data[][]={
{"a","lkg","alfa"},
{"b","ukg","beta"},
{"c","1st","gama"}
};

JTable jt = new JTable(data,colHd);
int V = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int H = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(jt,V,H);
c.add(jsp, BorderLayout.CENTER);
}
}
 
vesrak raju
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTable.java:20: error: constructor JTable in class JTable cannot be applied to given types;
JTable jt = new JTable(data,colHd);
^
required: no arguments
found: String[][],String[]
reason: actual and formal argument lists differ in length

if i remove "void" then i get the error like this

JTable.java:5: error: invalid method declaration; return type required
public init()
^
1 error

please help!!!
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rename your class. The JTable you're using inside your class is not javax.swing.JTable but your own class. You haven't defined any constructors so it only has the default constructor, which is public and has no arguments (public JTable() {}). That doesn't match the arguments you're giving and that's why you're getting a compiler error.

And welcome to the Ranch!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!