Article View: borland.public.jbuilder.java.swing
Article #13129Re: problems with JTABLE
From: Pierre LATECOERE
Date: Sat, 26 Sep 1998 00:00
Date: Sat, 26 Sep 1998 00:00
140 lines
4898 bytes
4898 bytes
Hi,
Here is some code that could help you. This method binds a JTable with a
DataSet. A table header is attached to the table.
I have develooped a complete new bean. If you need it let me know.
Pierre
pml@urbanet.ch
private void bindDataSet() {
TableColumn column = null;
if (dataSet != null)
{
pmTableModel dm = new pmTableModel(dataSet, this);
//DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
Table=new JTable(dm);
Table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
JTableHeader tH=new JTableHeader();
tH=Table.getTableHeader();
tH.setPreferredSize(new Dimension(1000, 15));
tH.setAutoscrolls(true);
tH.setVisible(true);
tH.setResizingAllowed(true);
try {
for (int j = 0; j < dataSet.getColumnCount(); j++)
{String t=dataSet.getColumn(j).getCaption();
column=Table.getColumnModel().getColumn(j);
column.setHeaderValue(t);
formt(j);
}//boucle j
tH.setUpdateTableInRealTime(false);}
catch (DataSetException e) {e.printStackTrace();}
this.setColumnHeaderView(tH);
this.getViewport().add(Table, null);
}
}
Anne JANSSENS <recherche@generix.fr> wrote in article
<6uge52$7v318@forums.borland.com>...
> 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:
<01bde957$0093ba70$4a4e26c2@cve-home-6-10>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<6uge52$7v318@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,cb2602e94755a9b3 X-Google-Attributes: gid111d45,public From: "Pierre LATECOERE" <pml@worldnet.net> Subject: Re: problems with JTABLE Date: 1998/09/26 Message-ID: <01bde957$0093ba70$4a4e26c2@cve-home-6-10> X-Deja-AN: 395058970 References: <6uge52$7v318@forums.borland.com> Organization: Another Netscape Collabra Server User Newsgroups: borland.public.jbuilder.java.swing