• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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: 22783
131
Eclipse IDE Spring VI Editor 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!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic