abstracttablemodel

java same ArrayList for multiple table model

*爱你&永不变心* 提交于 2019-12-06 05:29:12
I am struggling to avoid data duplication with multiple JTable. Basically I have a TableModel which has an arraylist of data and a string[] header. So far nothing new. Now I have another TableModel which has the same arraylist of data BUT a different string[] header. I can't make my code to work. I would appreciate some idea on how to share the arrayList of data across multiple table model. So when I change the data all models are updated and there isn't data duplication. I would like to avoid copy of arraylist any idea or am I wrong with this setup? I did try listener but I think going that

Using custom TableModel make isCellEditable true for a particular row on button click

邮差的信 提交于 2019-12-05 19:53:25
I have a table like above. Initially all the cells except button column are not editable. I have created the table using custom TableModel . My isCellEditable in custom TableModel looks like this: public boolean isCellEditable(int rowIndex, int columnIndex) { //System.out.println("isCellEditable: " + rowIndex + " " + columnIndex); if(getColumnClass(columnIndex) == JButton.class) return true; else return false; } But when I click on the Edit button of each row a JDialog will pop up with that row (by constructing a JTable in this dialog with only one row.) I can update the cell values in this

Create JTable from ArrayList

假装没事ソ 提交于 2019-12-02 19:27:32
问题 Now that I managed to put the objects from a file into a ArrayList , I have to display them into a JTable . These are the 3 objects contained in my ArrayList Lieu<Double, String>(45.573715, -73.900295, "p1"); Lieu<Double, String>(45.573882, -73.899748, "p2"); Lieu<Double, String>(45.574438, -73.900099, "p3"); In the Lieu class I have the methods getX() and getY() But I can't figure out how to diplay them in a JTable . Longitude Latitude 45.573715 -73.900295 45.573882 -73.899748 45.574438 -73

Row refreshing when cell is edited

时间秒杀一切 提交于 2019-12-02 11:14:30
问题 Im having problems with this JTable. I edit a cell like this Then i commit changes pressing enter. Here im hoping that table gui refresh with new values. But they aren't show, they are only show when i change selection like this fireTableCellUpdated( inRow, inCol ); is the method call when in the tableModel when i edit a cell. Im not sure if i have to add listener to the tableModel when fireTableCellUpdated to the jtable to repaint and revalidate. Some Code : This is called in the tableModel.

AbstractTableModel getValueAt perfomance

∥☆過路亽.° 提交于 2019-12-02 08:42:50
问题 I am newbie in JTable , maybe I don't understand something. Let's suppose I have ArrayList of 1000 Students ( id, name, surname, age ). And I want to show all students in JTable . As far as I understood I must create StudentTableModel that extends AbstractTableModel and set StudentTableModel to JTable . Therefore we can consider StudentTableModel as an "adapter" between our ArrayList and the table. On the internet I found such example implementation of getValueAt : public Object getValueAt

Create JTable from ArrayList

こ雲淡風輕ζ 提交于 2019-12-02 08:20:39
Now that I managed to put the objects from a file into a ArrayList , I have to display them into a JTable . These are the 3 objects contained in my ArrayList Lieu<Double, String>(45.573715, -73.900295, "p1"); Lieu<Double, String>(45.573882, -73.899748, "p2"); Lieu<Double, String>(45.574438, -73.900099, "p3"); In the Lieu class I have the methods getX() and getY() But I can't figure out how to diplay them in a JTable . Longitude Latitude 45.573715 -73.900295 45.573882 -73.899748 45.574438 -73.900099 Here's what I have for a start: public class MonModel extends AbstractTableModel{ @Override

JTable Sort Rows based on attribute not in table

故事扮演 提交于 2019-12-01 12:12:44
I wrote this simple sorting function : public void applyFilter(String filter, int col) { if(filter.length() == 0) sorter.setRowFilter(null); RowFilter<Object, Object> rf = null; try { rf = RowFilter.regexFilter(filter, col); } catch (java.util.regex.PatternSyntaxException e) { return; } sorter.setRowFilter(rf); refreshTable(); } But then I realized I wanted to filter the table based on an id that I haven't shown to the view(So it doesn't have it's column). The java filter is based on a column, but how can I filter the table based on other attributes that aren't displayed? I can easily fetch

JTable Sort Rows based on attribute not in table

主宰稳场 提交于 2019-12-01 10:52:37
问题 I wrote this simple sorting function : public void applyFilter(String filter, int col) { if(filter.length() == 0) sorter.setRowFilter(null); RowFilter<Object, Object> rf = null; try { rf = RowFilter.regexFilter(filter, col); } catch (java.util.regex.PatternSyntaxException e) { return; } sorter.setRowFilter(rf); refreshTable(); } But then I realized I wanted to filter the table based on an id that I haven't shown to the view(So it doesn't have it's column). The java filter is based on a column

create TableModel and populate jTable dynamically

为君一笑 提交于 2019-12-01 04:05:45
I want to store the results of reading lucene index into jTable, so that I can make it sortable by different columns. From index I am reading terms with different measures of their frequencies. Table columns are these : [string term][int absFrequency][int docFrequency][double invFrequency] So i in AbstractTableModel I can define column names, but i dont know how to get the Object[][]data with results from the following method: public static void FrequencyMap(Directory indexDir) throws Exception { List<ArrayList>redoviLista = new ArrayList<ArrayList>(); //final Map<String,TermRow> map = new

create TableModel and populate jTable dynamically

泄露秘密 提交于 2019-12-01 01:15:46
问题 I want to store the results of reading lucene index into jTable, so that I can make it sortable by different columns. From index I am reading terms with different measures of their frequencies. Table columns are these : [string term][int absFrequency][int docFrequency][double invFrequency] So i in AbstractTableModel I can define column names, but i dont know how to get the Object[][]data with results from the following method: public static void FrequencyMap(Directory indexDir) throws