tags:

views:

399

answers:

3

Hello All, I'm trying to create an applet which displays a simple table with no headers or other decoration. Could anyone be so kind as to show me the code for this? All the examples I've found haven't compiled or have included extra features which I don't need. A simple 2 x 2 table with empty cells and no headers is what I'm looking for. Thanks to all in advance...

Code for skaffman:

import java.applet.*;
import java.awt.*;
import java.awt.event.*;

public class danTeamProject extends Applet implements ActionListener
{
char[][] charValues = new char[10][10];
danTable aTable;
boolean allowUserInput = false;

public void init()
{
 Button BtnStart = new Button("Start");
 BtnStart.addActionListener((ActionListener)this); //cast
 this.add(BtnStart); //add action listener to button


 aTable = new danTable();
 aTable.setVisible(true);


}

public void paint(Graphics g)
{
    g.setColor(Color.black);
    aTable.draw(g);
}
public void actionPerformed(ActionEvent arg0)
{

}

}

and

import java.awt.*;
import java.util.*;
import javax.swing.*;

public class danTable extends JPanel
{



public danTable()
{

 // Create with initial data
Object[][] cellData = {
    {"row1-col1", "row1-col2"},
    {"row2-col1", "row2-col2"}};
String[] columnNames = {"col1", "col2"};

JTable table = new JTable(cellData, columnNames);

}

}

A: 

Create a JTable and add the table to a JPanel (instead of a JScrollPane) and the header will not appear. Read the JTable API and follow the link to the Swing tutorial on "How to Use Tables" for working examples.

camickr
I've read and re-read the "How to use Tables" tutorial, and when I try to compile and execute to code it provides I get lots of errors, which make it hard to comprehend what the tutorial is trying to help me understand
danwoods
Thanks for the first part though...
danwoods
Would you implement the first part like this? JTable table = new JTable(dataModel);JPanel panel = new JPanel(table);That produces a new error: ./danTable.java:23: cannot find symbolsymbol : constructor JPanel(javax.swing.JTable)location: class javax.swing.JPanel JPanel panel = new JPanel(table); ^
danwoods
If the above post does not make sense I can re-post as an answer or an edit...
danwoods
+1  A: 
OscarRyz
Thanks Oscar, that's exactly what I was looking for.
danwoods
A: 

Hi everyoneeeeee

Hi