tablemodel

JTableModelListener.tableChanged() thread safe?

僤鯓⒐⒋嵵緔 提交于 2019-12-11 07:57:42
问题 Is the tableChanged() call on a JTable thread safe, so that i am allowed to call it from another Thread, which for example finished downloading something? I imagine tableChanged() to just put a new Event into the Event queue, so that the Event-Dispatcher-Thread will update the JTable at some point in the future, but is this adding thread safe? 回答1: Short answer no, it is not thread safe and all calls to tableChanged should be made from within the context of the Event Dispatching Thread. If

Multiple instances of model components in Java Swing?

主宰稳场 提交于 2019-12-11 04:46:04
问题 Until now I had different model classes for the appropriate Java Swing component, for instance I have several TableModel for several JTable . Every JTable has its own TableModel . The TableModel is based on one object ( Model ), giving all the required data. Something like this: public class MyTableModel extends AbstractTableModel { Model model; But now I would like to make a change. My interface offers the possibility of multiple instances of Model . So my question is, what should I do?

Can't refresh my JTable with new data

痞子三分冷 提交于 2019-12-11 04:42:58
问题 I create a JTable when the frame is intially created, but create an empty AbstractTableModel which I extended. Then the user has to select something from a JComboBox and the user can preview the messages dealing with that specified selection. When the preview button is clicked, I create a new AbstractTableModel with the new data and set that model to a newly created JTable object. Once that is done, I call AbstractTableModel.fireTableDataChanged , JTable.repaint() , JTable.validate() JFrame

The right approach to update complex JTables, TableModel and others

纵饮孤独 提交于 2019-12-11 03:12:54
问题 My GUI shows the vehicles in my park , and vehicles that I want to set availables in two different VehicleTables (classes that extend JTable). For availables I intend that these vehicles can be observed from an agent (third-part software). Both the tables show the descriptions of Vehicles in the rows...for this I have created VehicleTableModel and Vehicle classes. The Vehicle class is an abstract class and his subclasses are: Car, Truck, Trailer, etc. . You can see a snapshot of my software:

Moving a row in jTable

故事扮演 提交于 2019-12-09 16:01:35
问题 How can one move a row in jTable so that row1 goes to row2 's position and row2 goes to row1 's position ? 回答1: Use the moveRow(...) method of the DefaultTableModel . Or, if you aren't using the DefaultTableModel then implement a simliar method in your custom model. 回答2: Here is my code that I've just developed using the answer in this question. With those function you can select multiple rows at a time and move them down or up in a JTable . I've attached those function to JButton , but i

Java JTable getting the data of the selected row

流过昼夜 提交于 2019-12-05 21:17:26
问题 Are there any methods that are used to get the data of the selected row ? I just want to simply click a specific row with data on it and click a button that will print the data in the Console. 回答1: http://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html You will find these methods in it: getValueAt(int row, int column) getSelectedRow() getSelectedColumn() Use a mix of these to achieve your result. 回答2: You can use the following code to get the value of the first column of the

JTable + TableModel cache fetch event for lazy instantiation?

橙三吉。 提交于 2019-12-05 08:55:44
问题 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

JDBC TableModel for a JTable in Java?

不想你离开。 提交于 2019-12-04 17:14:55
I want to display a database table as a JTable. I have never used JTable before so I googled JTable and TableModel. With that googling, I am able to write my own custom TableModel which show data stored in Object[][] data; Now, I want to show my database table data into JTable. I searched that also and have got an idea of that but still confused about what should goes where in the implementation class of AbstractTableModel. Following is the code of custom TableModel. public abstract class AbstractPOLDATTableModel extends AbstractTableModel { protected boolean DEBUG = false; private String[]

Moving a row in jTable

孤者浪人 提交于 2019-12-04 03:51:25
How can one move a row in jTable so that row1 goes to row2 's position and row2 goes to row1 's position ? Use the moveRow(...) method of the DefaultTableModel . Or, if you aren't using the DefaultTableModel then implement a simliar method in your custom model. LAL Here is my code that I've just developed using the answer in this question. With those function you can select multiple rows at a time and move them down or up in a JTable . I've attached those function to JButton , but i clean them out to make them more readable. The last code line of both method ( setRowSelectionInterval() ) is

Java JTable getting the data of the selected row

╄→гoц情女王★ 提交于 2019-12-04 03:43:44
Are there any methods that are used to get the data of the selected row ? I just want to simply click a specific row with data on it and click a button that will print the data in the Console. ManyQuestions http://docs.oracle.com/javase/7/docs/api/javax/swing/JTable.html You will find these methods in it: getValueAt(int row, int column) getSelectedRow() getSelectedColumn() Use a mix of these to achieve your result. You can use the following code to get the value of the first column of the selected row of your table. int column = 0; int row = table.getSelectedRow(); String value = table