Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

please help with JTable

Status
Not open for further replies.

DPUser

Technical User
Oct 17, 2003
16
US
I am trying to create a JTable that is a 3X3 grid. I have managed to get a JTable to display on the screen. However, I cannot get the JTable to have just 3 columns and 3 rows. Can someone please help.

The code is as follows:

import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;


public class Frame1 extends JFrame{
private String [] colHeads ={ "Planet", "Radius", "Moons","Gaseous","Color"};
private Object[] cells ={"Mercury",new Double(2440),new Integer(0),Boolean.FALSE, Color.yellow};
private DefaultTableModel model = new DefaultTableModel(colHeads,0);
private JTable table = new JTable(model);
private JScrollPane scroll = new JScrollPane(table);

private JTabbedPane tabbedPane = new JTabbedPane();
private JScrollPane mainScroll = new JScrollPane(tabbedPane);
private JPanel topPane= new JPanel();
private JPanel outerPane = new JPanel();
private JPanel buttomPane = new JPanel();

public static void main(String[] args){
JFrame f = new Frame1();
f.show();
}
public Frame1(){
setSize(900,900);
setVisible(true);
Container contentPane = getContentPane();
tabbedPane.addTab("Log in",outerPane);
outerPane.setLayout(new BorderLayout() );
buttomPane.add(new Button() );
topPane.setSize(200,200);
outerPane.add(topPane,"North");
outerPane.add(buttomPane, "South");

topPane.add(scroll);
outerPane.setBorder( BorderFactory.createEtchedBorder() );
topPane.setBorder( BorderFactory.createEtchedBorder() );
buttomPane.setBorder( BorderFactory.createEtchedBorder() );
contentPane.add(mainScroll);
for (int i=0;i<100;i++)
model.addRow(cells);
}
}
------------
Thank you
 
I didn't know, until now, that there was as special forum for JBuilder. I see that you don't get responses on questions like these for months. For questions that are pure java, try one of the java forums especially

forum269

Most of the time you'll have an answer the same day.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top