Skip to main content

somebody who can get me a sample ,how can i load date into JXTable?

1 reply [Last post]
zzsnake
Offline
Joined: 2006-03-20
Points: 0

i want to load XML date or from database ,and show it in jxttable.how can i do it?
get me a sample.
tks

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
yael800
Offline
Joined: 2006-09-27
Points: 0

[code]
import java.awt.Color;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionAdapter;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import javax.swing.JComponent;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellRenderer;

import org.jdesktop.binding.swingx.adapter.DataModelToTableModelAdapter;
import org.jdesktop.dataset.DataSet;
import org.jdesktop.dataset.adapter.TabularDataModelAdapter;
import org.jdesktop.dataset.provider.sql.JDBCDataConnection;
import org.jdesktop.dataset.provider.sql.SQLCommand;
import org.jdesktop.dataset.provider.sql.SQLDataProvider;
import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.decorator.AlternateRowHighlighter;
import org.jdesktop.swingx.decorator.Highlighter;
import org.jdesktop.swingx.decorator.HighlighterPipeline;
import org.jdesktop.swingx.table.TableColumnExt;
/public class MyTable{

private JXTable jxTable;

private DataTable dataTable;

private TabularDataModelAdapter tabAdapter;

private SQLDataProvider provider;

private DataModelToTableModelAdapter tableModelAdapter;

private SQLCommand sqlCommand;

public MyTable () {

}

public JComponent init() {
// TODO code application logic here
DataSet ds = new DataSet();
dataTable = new DataTable(ds);
dataTable.createColumns();

// JDBC:
provider = new SQLDataProvider();

JDBCDataConnection dataConnection = MyConnection.getInstance()
.getDataConnection();

dataConnection.setConnected(true);
provider.setConnection(dataConnection);

sqlCommand = new SQLCommand();
String strSql = "SELECT * FROM table_name";
sqlCommand.setSelectSQL(strSql);
provider.setCommand(sqlCommand);

tabAdapter = new TabularDataModelAdapter(dataTable);

tableModelAdapter = new DataModelToTableModelAdapter(tabAdapter);

jxTable.setModel(tableModelAdapter);
jxTable.setAutoCreateColumnsFromModel(false);

provider.load(dataTable);
dataTable.clear();
dataTable.load();

jxTable.setColumnControlVisible(true);
return new JScrollPane(jxTable);
}
}
[/code]