Skip to main content

Bug in getColumnExt in DefaultTableColumnModelExt?

5 replies [Last post]
odoremieux
Offline
Joined: 2004-03-30
Points: 0

When no identifier has been set, the method work with no problem, but when an identifier is set, it always fail.

Souldn't the code be something like that?

public TableColumnExt getColumnExt(Object identifier) {
for (Iterator iter = initialColumns.iterator(); iter.hasNext();) {
TableColumn column = iter.next();
if((column instanceof TableColumnExt) && (identifier.equals(column.getIdentifier()))) {
return (TableColumnExt) column;
}else if ((column instanceof TableColumnExt) && (identifier instanceof TableColumnExt) && (((TableColumnExt)identifier).getIdentifier().equals(column.getIdentifier()))) {
return (TableColumnExt) column;
}
}
return null;
}

I am not 100% that's the solution, but's working for me.

Thanks,

Olivier Doremieux

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Kleopatra

jdnc-interest@javadesktop.org schrieb:
> Here we go
> Run the example, click on the header to sort a column and then click on the button.
> It always says that the sorting order is "unsorted"
> I did some debuging and the "problem" comes from JXTable in getSortOrder.
> TableColumnExt columnExt = getColumnExt(identifier); always return null
>

hmm, actually ... no - the problem comes from your code ;-)

>
> private void processIt(ActionEvent e) {
> TableColumn sortingColum = myTable.getSortedColumn();
> System.out.println("Sorting column " + sortingColum.getIdentifier());
> SortOrder mySortingOrder = myTable.getSortOrder(sortingColum);
> System.out.println("Sorting Order " + mySortingOrder);
> }

the object parameter in getSortOrder must be the column's identifier
instead of the column itself. Following works as expected (my expectation :)

[code]
SortOrder mySortingOrder = myTable.getSortOrder(
sortingColumn.getIdentifier());
[/code]

HTH
Jeanette

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

odoremieux
Offline
Joined: 2004-03-30
Points: 0

My Bad.

Thanks for the update.

Olivier

Kleopatra

jdnc-interest@javadesktop.org schrieb:
> When no identifier has been set, the method work with no problem, but when an identifier is set, it always fail.
>

Hmm .. do you have a small (!) runnable example demonstrating the
problem .. because I don't understand what you are trying to do (from
your solution - why should the identifier be of type TableColumnExt?).

Thanks
Jeanette

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

odoremieux
Offline
Joined: 2004-03-30
Points: 0

Here we go
Run the example, click on the header to sort a column and then click on the button.
It always says that the sorting order is "unsorted"
I did some debuging and the "problem" comes from JXTable in getSortOrder.
TableColumnExt columnExt = getColumnExt(identifier); always return null

That's why I changed getColumnExt in DefaultTableColumnModelExt

------------------------------------------------------------------
package test;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.WindowConstants;
import javax.swing.table.TableColumn;

import org.jdesktop.swingx.JXTable;
import org.jdesktop.swingx.decorator.SortOrder;
import org.jdesktop.swingx.table.TableColumnExt;

public class TestJXTable extends JFrame {
private String columnNames[];
private String dataValues[][];
private JXTable myTable;

public TestJXTable() {
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
initComponents();
setSize(400, 500);
setVisible(true);
}

private void initComponents() {
JButton jb1 = new JButton("Do it");
jb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
processIt(e);
}
});
add(jb1,BorderLayout.NORTH);
// Create columns
CreateColumns();
CreateData();

// Create a new table instance
myTable = new JXTable(dataValues, columnNames);
JScrollPane scrollPane = new JScrollPane(myTable);
add(scrollPane, BorderLayout.CENTER);
}

public void CreateColumns() {
// Create column string labels
columnNames = new String[8];

for (int iCtr = 0; iCtr < 8; iCtr++)
columnNames[iCtr] = "Col:" + iCtr;
}

public void CreateData() {
// Create data for each element
dataValues = new String[100][8];

for (int iY = 0; iY < 100; iY++) {
for (int iX = 0; iX < 8; iX++) {
dataValues[iY][iX] = "" + iX + "," + iY;
}
}
}

private void processIt(ActionEvent e) {
TableColumn sortingColum = myTable.getSortedColumn();
System.out.println("Sorting column " + sortingColum.getIdentifier());
SortOrder mySortingOrder = myTable.getSortOrder(sortingColum);
System.out.println("Sorting Order " + mySortingOrder);
}

public static void main(String[] args) {
TestJXTable testJXTable = new TestJXTable();
}
}

Let me know if you need someting else.

Olivier Doremieux

odoremieux
Offline
Joined: 2004-03-30
Points: 0

Apparently my example is too big for the forum.
You can get the file at :

http://www.jigkids.com/TestJXTable.java

Let me know if you need someting else

Olivier Doremieux