tablemodel

JTable + TableModel cache fetch event for lazy instantiation?

℡╲_俬逩灬. 提交于 2019-12-03 20:28:22
Scenario: you are using a JTable with a custom TableModel to view the contents of some collection located in a database or on the network or whatever. The brute force way to make this work is to load the whole collection at once. Let's say that isn't practical because of the resources needed. The simple way around that problem is to fetch rows on demand, one row at a time, as the JTable renders each row, and calls TableModel.getValueAt(); cache as necessary. This causes a lot of hits to the database, though. Is there a way to listen to scroll/viewport events for a JTable, to figure out what

Preserve JTable selection across TableModel change

折月煮酒 提交于 2019-12-03 05:22:51
We're seeing JTable selection get cleared when we do a fireTableDataChanged() or fireTableRowsUpdated() from the TableModel . Is this expected, or are we doing something wrong? I didn't see any property on the JTable (or other related classes) about clearing/preserving selection on model updates. If this is default behavior, is there a good way to prevent this? Maybe some way to "lock" the selection before the update and unlock after? The developer has been experimenting with saving the selection before the update and re-applying it. It's a little slow. This is Java 1.4.2 on Windows XP, if

implement AbstractTableModel for a Java collection

偶尔善良 提交于 2019-12-02 04:03:48
问题 I'm trying to implement an AbstractTableModel for a collection named "clients" but I keep receiving the error "required variable found value" for the "add" method. Here is my code: I'm sorry for the confusion created. The add method is meant to add a new client in the table (by that I mean a new row). I don't want to add a new client to the collection. class ModelTabel extends AbstractTableModel{ public int getRowCount() { return clients.size(); } public int getColumnCount() { return 4; }

Complex use of JTable, TableModel and others

好久不见. 提交于 2019-12-01 14:31:45
I have some problems with the manage of two JTable, and relative data. I had make this GUI: I explain the use: In the first jTable I have a list of vehicles (trucks, cars...) and relative info. In the second jTable I have a list of vehicles that I want make "available" (i.e. a sw agent starts), with the press of the green arrow. So, is a sublist of the first list: the row selected in the first table are copied in the second. First problem: In the first column I have a explicative image of the kind of vehicle (you can see a truck in the example). In the third and fifth column I have different

Complex use of JTable, TableModel and others

喜夏-厌秋 提交于 2019-12-01 12:29:50
问题 I have some problems with the manage of two JTable, and relative data. I had make this GUI: I explain the use: In the first jTable I have a list of vehicles (trucks, cars...) and relative info. In the second jTable I have a list of vehicles that I want make "available" (i.e. a sw agent starts), with the press of the green arrow. So, is a sublist of the first list: the row selected in the first table are copied in the second. First problem: In the first column I have a explicative image of the

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

Swing: catching exceptions from TableModel

走远了吗. 提交于 2019-11-30 06:05:01
问题 I have a TableModel that may throw an exception on its setValueAt method if user enters an invalid value: public class MyTableModel extends AbstractTableModel { public void setValueAt(Object value, int rowIndex, int columnIndex) { String valueStr = (String) value; // some basic failure state if(valueStr.length()>5) { throw new ValidationException("Value should have up to 5 characters"); } this.currentValue = valueStr; } } Question is: how can another class catch this exception? It may show a

JTable reading text files from second line

狂风中的少年 提交于 2019-11-29 18:12:31
I'm working on JTable that reads text from a .txt file. the txt file gets updated dynamically after 3 sec. Now when I run the application, everything is good except that the output of .txt files comes in JTable from the second line. The first line of txt file doesn't appear on my JTable. Can anyone help? Here's the code: public class InterfaceFrame extends JFrame implements ActionListener{ public static void main(String[] args) throws URISyntaxException, IOException, InterruptedException { panel.setSize(100,100); panel.add(table); model.fireTableStructureChanged(); table.setModel(model);

How to add data to JTable created in design mode?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 18:08:50
I created an initial JFrame that contains a table with three columns, as shown below: This JFrame was created in design mode, and so now in the panel's constructor, I want to load some data so when the user selects to open this JFrame, the data is loaded. My column data types are Object (generally 'Status' is for an image representing the status of the share - active or inactive), String for the share's name and integer for the number of active clients connected to that share. My question is, how to I add rows to a JTable via code? In a simplified way (can be improved): class MyModel extends