Article View: borland.public.jbuilder.java.swing
Article #13127problems with JTABLE
From: Anne JANSSENS
Date: Fri, 25 Sep 1998 00:00
Date: Fri, 25 Sep 1998 00:00
93 lines
3440 bytes
3440 bytes
hello,
I want to use a JTable but with jbuilder 2.0 I am not able to see the header
(column names) of my table, and of
course I can't sort my table nor move my columns.
When I use for the same example javac from the jdk1.2beta4 I have no
problems !
What's wrong ?
Thanks for answering, Anne
ps : here is the code example from sun
import com.sun.java.swing.JTable;
import com.sun.java.swing.JScrollPane;
import com.sun.java.swing.JPanel;
import com.sun.java.swing.JFrame;
import java.awt.*;
import java.awt.event.*;
public class SimpleTableDemo extends JFrame {
private boolean DEBUG = true;
public SimpleTableDemo() {
super("SimpleTableDemo");
Object[][] data = {
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Chasing toddlers", new Integer(2), new Boolean(false)},
{"Mark", "Andrews",
"Speed reading", new Integer(20), new Boolean(true)},
{"Angela", "Lih",
"Teaching high school", new Integer(4), new Boolean(false)}
};
String[] columnNames = {"First Name",
"Last Name",
"Sport",
"# of Years",
"Vegetarian"};
final JTable table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
if (DEBUG) {
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
printDebugData(table);
}
});
}
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
//Add the scroll pane to this window.
setContentPane(scrollPane);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
private void printDebugData(JTable table) {
int numRows = table.getRowCount();
int numCols = table.getColumnCount();
com.sun.java.swing.table.TableModel model = table.getModel();
System.out.println("Value of data: ");
for (int i=0; i < numRows; i++) {
System.out.print(" row " + i + ":");
for (int j=0; j < numCols; j++) {
System.out.print(" " + model.getValueAt(i, j));
}
System.out.println();
}
System.out.println("--------------------------");
}
public static void main(String[] args) {
SimpleTableDemo frame = new SimpleTableDemo();
frame.pack();
frame.setVisible(true);
}
}
Technical Details
Message-ID:
<6uge52$7v318@forums.borland.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,cb2602e94755a9b3,start X-Google-Attributes: gid111d45,public From: "Anne JANSSENS" <recherche@generix.fr> Subject: problems with JTABLE Date: 1998/09/25 Message-ID: <6uge52$7v318@forums.borland.com> X-Deja-AN: 394765520 Organization: Another Netscape Collabra Server User X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 Newsgroups: borland.public.jbuilder.java.swing