Comments (3)
TableRowFilterSupport
creates it is own instance if TableRowSorter
. Also calling convertRowIndexToModel
on a row sorter is not correct - it is better be called on the table itself without any knowledge of internals (sorter in this case)
from oxbow.
I am not using a tablerowsorter, however I still see this bug.
- Click on the number 3 in the "Ints" column.
- Sort the column so that the number 3 is at the top
- Filter the column "Ints" to only display number 3
import java.awt.BorderLayout;
import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
import com.ezware.oxbow.swingbits.table.filter.IFilterChangeListener;
import com.ezware.oxbow.swingbits.table.filter.ITableFilter;
import com.ezware.oxbow.swingbits.table.filter.TableRowFilterSupport;
import com.ezware.oxbow.swingbits.table.filter.JTableFilter;
public class TableFilter2 implements ListSelectionListener {
final JTable table;
JTableFilter tableFilter;
private int selectedRow = -1;
private int selectedColumn = -1;
private int index = 1;
public TableFilter2() {
final String[] cols = { "Checkbox", "Ints", "Strings", "Bools", "test" };
Object[][] data = { { false, 1, "A", false, "hide" },
{ false, 1, "B", false, "hide" },
{ false, 1, "C", false, "hide" },
{ false, 3, "C", false, "hide" } };
final DefaultTableModel model = new DefaultTableModel(data, cols);
table = new JTable(model) {
@Override
public boolean isCellEditable(int row, int col) {
return false;
}
};
table.getSelectionModel().setSelectionMode(
ListSelectionModel.SINGLE_SELECTION);
table.getSelectionModel().addListSelectionListener(this);
table.getColumnModel().getSelectionModel()
.addListSelectionListener(this);
table.setRowSorter(null);
table.setAutoCreateRowSorter(false);
table.getTableHeader().setReorderingAllowed(false);
tableFilter = new JTableFilter(table);
tableFilter.addChangeListener(new IFilterChangeListener() {
@Override
public void filterChanged(ITableFilter<?> arg0) {
System.out.println("Fitler Event");
}
});
TableRowFilterSupport.forFilter(tableFilter).searchable(true).apply();
TableColumn tc = table.getColumnModel().getColumn(0);
tc.setCellEditor(table.getDefaultEditor(Boolean.class));
tc.setCellRenderer(table.getDefaultRenderer(Boolean.class));
JPanel panel = new JPanel(new BorderLayout());
panel.add(new JScrollPane(table), BorderLayout.CENTER);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(panel);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
new TableFilter2();
}
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting()) {
return;
}
if (table.getSelectedRow() == -1 || table.getSelectedColumn() == -1) {
return;
}
if (selectedRow == table.convertRowIndexToModel(table.getSelectedRow())
&& selectedColumn == table.convertRowIndexToModel(table
.getSelectedColumn())) {
return;
}
selectedRow = table.convertRowIndexToModel(table.getSelectedRow());
selectedColumn = table
.convertRowIndexToModel(table.getSelectedColumn());
System.out.println("Row/Col " + selectedRow + " / " + selectedColumn);
System.out.println(index++ + " " + e);
}
}
Error:
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 1
at javax.swing.DefaultRowSorter.convertRowIndexToModel(DefaultRowSorter.java:518)
at javax.swing.JTable.convertRowIndexToModel(JTable.java:2645)
at TableFilter2.valueChanged(TableFilter2.java:102)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:184)
at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSelectionModel.java:154)
at javax.swing.DefaultListSelectionModel.setValueIsAdjusting(DefaultListSelectionModel.java:685)
at javax.swing.JTable$SortManager.restoreSelection(JTable.java:4052)
at javax.swing.JTable$SortManager.processChange(JTable.java:4000)
at javax.swing.JTable.sortedTableChanged(JTable.java:4132)
at javax.swing.JTable.sorterChanged(JTable.java:3822)
at javax.swing.RowSorter.fireRowSorterChanged(RowSorter.java:340)
at javax.swing.RowSorter.fireRowSorterChanged(RowSorter.java:332)
at javax.swing.DefaultRowSorter.sort(DefaultRowSorter.java:612)
at javax.swing.DefaultRowSorter.setRowFilter(DefaultRowSorter.java:424)
at com.ezware.oxbow.swingbits.table.filter.JTableFilter.execute(JTableFilter.java:69)
at com.ezware.oxbow.swingbits.table.filter.AbstractTableFilter.apply(AbstractTableFilter.java:113)
at com.ezware.oxbow.swingbits.table.filter.TableFilterColumnPopup.applyColumnFilter(TableFilterColumnPopup.java:203)
at com.ezware.oxbow.swingbits.table.filter.TableFilterColumnPopup.access$6(TableFilterColumnPopup.java:199)
at com.ezware.oxbow.swingbits.table.filter.TableFilterColumnPopup$5.perform(TableFilterColumnPopup.java:180)
at com.ezware.oxbow.swingbits.popup.PopupWindow$CommandAction.actionPerformed(PopupWindow.java:161)
from oxbow.
Please ignore this bug post. The bug is actually due to me trying to convert a table column index to a model rowIndex.
Thanks
Chris
from oxbow.
Related Issues (20)
- Support custom ActionListeners for Command Buttons
- ComponentOrientation problem HOT 4
- Maven repository ? HOT 5
- Re-sizing the jpopupmenu HOT 15
- firetablestructurechanged preserves filter state but resets the table header renderer
- TableRowFilterSupport only sorting not filtering? HOT 3
- Support for custom rendering of DistinctColumnItem in TableFilterColumnPopup HOT 2
- Icon lost in TableHeader when Column is sorted HOT 2
- Broken download links (latest releases) HOT 1
- No compatibility with latest miglayout version HOT 2
- How can change foreground in the header? HOT 3
- Add custom actions
- How get and set Filter table? HOT 1
- Filtering with RegExp
- When is next release? HOT 3
- Table flicker on refresh when filter or sort applied
- Choice dialog - focus problem on java >= 9 HOT 1
- Lack of license HOT 4
- Travis Build fails HOT 1
- How to clear all filters HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from oxbow.