craftleft.gif (3002 bytes)QuickTable
Home | API | Tutorial | Download | Support | Contact topblack.gif (108 bytes)


QuickTable User Cp  |  Register  |  Members  |  Search  |  Help
    |- QuickTable Discussion Forums > QuickTable Installation Issues Post New Topic   Post A Reply
Merge Cells printer friendly version
next newest post | next oldest post
Author Messages
Vishal
Private First Class

Gender: Male
Location: Williamstown, MA
Registered: Jul 2004
Status: Offline
Posts: 12

Click here to see the profile for Vishal Send email to Vishal Send private message to Vishal Find more posts by Vishal Edit or delete this message Reply w/Quote
Posted Thursday, August 26, 2004 @ 16:48:31    ICQ  YIM

Can we merge cells in DBTable?

Just in Excel, we can merge a few cells together(even in same row would be good) can we do something like that in DBTable? Basically my table data is grouped and I programmatically insert the group name row so the viewer can see those group name. The problem is that group names are much bigger than data, so if I make the column which contains those group name wider the view does not look that pretty. Is there a better way?

--------------------

Vishal
Private First Class

Gender: Male
Location: Williamstown, MA
Registered: Jul 2004
Status: Offline
Posts: 12

Click here to see the profile for Vishal Send email to Vishal Send private message to Vishal Find more posts by Vishal Edit or delete this message Reply w/Quote
Posted Tuesday, March 22, 2005 @ 18:03:00    ICQ  YIM

To have merging cells capabilities, I tried using Table model provided at:
http://codeguru.earthweb.com/java/articles/139.shtml

I've downloaded their source code and I'm trying to use that with DBTable. Here's the code I used to merge cells at column 0 & 1 on row 0

JTable table = this.getTable();

AttributiveCellTableModel ml = new AttributiveCellTableModel();
CellSpan cellAtt =(CellSpan)ml.getCellAttribute();
int[] rows = {0};
int[] cols = {0,1}; //merging cells at column 0 & 1
cellAtt.combine(rows,cols);
table.setModel(ml);
refresh(data);

When I try to execute this, I get a runtime error:
Exception in thread "main" java.lang.StackOverflowError

Any clues????

--------------------

Admin
Board Owner

Gender: Unspecified
Location:
Registered: Jul 2003
Status: Offline
Posts: 9

Click here to see the profile for Admin Send email to Admin Send private message to Admin Find more posts by Admin Edit or delete this message Reply w/Quote
Posted Tuesday, March 22, 2005 @ 22:23:26  

This code doesn't use JTable instead it uses MultiSpanCellTable. QuickTable is not setup use MultiSpanCellTable. Unfortunately quicktable doesn't have the merge cell feature. I would suggest you to use the MultiSpanCellTable to show merged cells instead of quicktable.
Joshua S. Weinstein
Unregistered
Edit or delete this message Reply w/Quote
Posted Tuesday, January 8, 2008 @ 23:05:59  

Code:

// Changes below will allow AttributiveCellTableModel to work without the Overflow Exception

/*
* (swing1.1beta3)
*
*/

package jp.gr.java_conf.tame.swing.table;

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

/**
* @version 1.0 11/22/98
*/

public class AttributiveCellTableModel extends DefaultTableModel {

protected CellAttribute cellAtt;

public AttributiveCellTableModel() {
this((Vector)null, 0);
}
public AttributiveCellTableModel(int numRows, int numColumns) {
Vector names = new Vector(numColumns);
names.setSize(numColumns);
setColumnIdentifiers(names);
dataVector = new Vector(numRows);
dataVector.setSize(numRows);
setNumRows(numRows);
cellAtt = new DefaultCellAttribute(numRows,numColumns);
}
public AttributiveCellTableModel(Vector columnNames, int numRows) {
setColumnIdentifiers(columnNames);
dataVector = new Vector();
setNumRows(numRows);
cellAtt = new DefaultCellAttribute(numRows,columnNames.size());
}
public AttributiveCellTableModel(Object[] columnNames, int numRows) {
this(convertToVector(columnNames), numRows);
}
//Joshua S. Weinstein: Avoid overflow error in Java 1.5
public AttributiveCellTableModel(Vector data, Vector columnNames) {
super.setDataVector(data, columnNames);
mySetDataVector(data, columnNames);
}
//Joshua S. Weinstein: Avoid overflow error in Java 1.5
public AttributiveCellTableModel(Object[][] data, Object[] columnNames) {
super.setDataVector(data, columnNames);
//mySetDataVector(data, columnNames);
doChange(data.length, columnNames.length);
}


// Joshua S. Weinstein: Avoid overflow error in Java 1.5
protected void mySetDataVector(Vector newData, Vector columnNames) {
if (newData == null)
throw new IllegalArgumentException("setDataVector() - Null parameter");
// dataVector = new Vector(0);
if (columnNames != null) setColumnIdentifiers(columnNames);
dataVector = newData;

doChange(dataVector.size(),
columnIdentifiers.size());

}

protected void doChange(int dataSize,int columnSize) {
//
cellAtt = new DefaultCellAttribute(dataSize,
columnSize);

newRowsAdded(new TableModelEvent(this, 0, getRowCount()-1,
TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
}

public void addColumn(Object columnName, Vector columnData) {
if (columnName == null)
throw new IllegalArgumentException("addColumn() - null parameter");
columnIdentifiers.addElement(columnName);
int index = 0;
Enumeration enumeration = dataVector.elements();
while (enumeration.hasMoreElements()) {
Object value;
if ((columnData != null) && (index < columnData.size()))
value = columnData.elementAt(index);
else
value = null;
((Vector)enumeration.nextElement()).addElement(value);
index++;
}

//
cellAtt.addColumn();

fireTableStructureChanged();
}

public void addRow(Vector rowData) {
Vector newData = null;
if (rowData == null) {
newData = new Vector(getColumnCount());
}
else {
rowData.setSize(getColumnCount());
}
dataVector.addElement(newData);

//
cellAtt.addRow();

newRowsAdded(new TableModelEvent(this, getRowCount()-1, getRowCount()-1,
TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
}

public void insertRow(int row, Vector rowData) {
if (rowData == null) {
rowData = new Vector(getColumnCount());
}
else {
rowData.setSize(getColumnCount());
}

dataVector.insertElementAt(rowData, row);

//
cellAtt.insertRow(row);

newRowsAdded(new TableModelEvent(this, row, row,
TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT));
}

public CellAttribute getCellAttribute() {
return cellAtt;
}

public void setCellAttribute(CellAttribute newCellAtt) {
int numColumns = getColumnCount();
int numRows = getRowCount();
if ((newCellAtt.getSize().width != numColumns) ||
(newCellAtt.getSize().height != numRows)) {
newCellAtt.setSize(new Dimension(numRows, numColumns));
}
cellAtt = newCellAtt;
fireTableDataChanged();
}

/*
public void changeCellAttribute(int row, int column, Object command) {
cellAtt.changeAttribute(row, column, command);
}

public void changeCellAttribute(int[] rows, int[] columns, Object command) {
cellAtt.changeAttribute(rows, columns, command);
}
*/

}


Y0S4n
Unregistered
Edit or delete this message Reply w/Quote
Posted Thursday, October 29, 2009 @ 03:09:29  

Joshua,
Please give me sample to use your syntax

Thank
!@#$ !@#$ !@#$

Post New Topic   Post A Reply Jump to:
Contact Us | QuickTable - A Java DBGrid | Privacy Policy All times are GMT -5 Hours.
Welcome to QuickTable Forums, Guest!  
Login
Username :
Password :
In order to fully utilize the abilities of this board, you are required to register as a member. Registration is free, and allows you to do lots of things including turning on or off certain features of this board. Register now!
Powered by CuteCast v2.0 BETA 2
Copyright © 2001-2003 ArtsCore Studios