• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

JTable

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!!!
 
Sheriff
Posts: 22802
131
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
It's a beautiful day in this neighborhood - Fred Rogers. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic