Sun Mar 29, 2009 2:58 pm
Mon Apr 20, 2009 1:29 pm
Wed Sep 22, 2010 12:59 pm
Thu Oct 27, 2011 12:00 am
import java.awt.Color;
import java.awt.Dimension;
import java.util.Vector;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableColumnModel;
import javax.swing.table.TableModel;
public class TableExample extends JTable {
private static TableExample dataTable = null;
private static Vector<String> colsNames;
private TableExample() {
}
private TableExample(Object[] headers, Object[][] rows) {
super(rows, headers);
setShowGrid(true);
setAutoscrolls(true);
setSize(800, 600);
setColumnSelectionAllowed(true);
JTableHeader header = getTableHeader();
header.setBackground(Color.BLUE);
SetColsWidth(this);
Dimension dim = new Dimension(20, 1);
setIntercellSpacing(new Dimension(dim));
SetRowHight(this);
setAutoResizeMode(AUTO_RESIZE_OFF);
setModel(dataModel);
}
public static TableExample getInstance() {
if (dataTable == null) {
dataTable.createDatatableCols();
dataTable = new TableExample();
}
return dataTable;
}
public static TableExample getInstance(Object[] headers, Object[][] rows) {
if (dataTable == null) {
dataTable.createDatatableCols();
dataTable = new TableExample(headers, rows);
}
return dataTable;
}
public final static void createDatatableCols() {
colsNames = new Vector<String>();
colsNames.add("column name1");
colsNames.add("column name2");
colsNames.add("column name3");
colsNames.add("column name4");
colsNames.add("column name5");
colsNames.add("column name6");
colsNames.add("column name7");
colsNames.add("column name8");
//Class
colsNames.add("column name9");
colsNames.add("column name10");
colsNames.add("column name11");
colsNames.add("column name12");
colsNames.add("column name13");
colsNames.add("column name14");
}
public void updateDataModel(Vector<Vector> iReservations) {
System.out.println("Cols number" + colsNames.size());
System.out.println("Rows number" + iReservations.size());
TableModel tableModel = new DefaultTableModel(iReservations, colsNames);
setModel(tableModel);
}
public void SetRowHight(JTable table) {
int height = table.getRowHeight();
table.setRowHeight(height + 10);
}
public void SetColsWidth(JTable table) {
TableColumnModel columnModel = table.getColumnModel();
int width = 100;
columnModel.setColumnMargin(10);
}
}
Wed Jan 18, 2012 8:48 am
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.