Currently im doing on a project on ordering system. Let me explain the flow of the system. In ordering class, i have 2 jtable. One of the jtables shows the list of food retrieve from the database. I just have to click on one of the food and press"add", the selected food will transfer to another jtable . After i press"proceed" i will be led to a jtable, to the next jpanel, which consists of the food i have selected. However" i allow one cell to be editable,"quantity" is there any way on how to retrieve the data input by the user and store to database?
Depending on the implementation of the TableModel, you could get the data for an individual row. This would, generally, be the preferred solution, as the data for the row would be encapsulated within a POJO which maintains all the data that you need in a single place that easily manageable.
If you've just dumped a bunch of unassociated properties into the table, you will need to use something like JTable#getValueAt or TableModel#getValueAt
See How to Use Tables for more details
Related
What I want is to create a list where each item in that list is an data table like below: http://imgur.com/a/mQdi5 Example data table The user needs to be able to sort items in the data table and needs to be able to sort the data tables itself.
Each table is going to represent a client and each item in that table is an order. The user will then collect the orders, if he collected an order the order wil dissapear but the user is also able to bring them back.
I've tried to put a Recyclerview inside a Recyclerview but this caused unitended side effects and bugs, also I read online that it is basically a bad practice. My initial intention was to use a recylcerview with a sortedlist.
I did some searching online and a lot of people recommended using categories between items so that you only need one list. But because I have data tables (CardViews) that can be independent sorted this isn't an option.
If anyone want to give me a nudge in the right direction, I would be really thankful.
I am writing an application that uses a JTable containing a model (DefaultTableModel). Now after working on it for some time I am not really sure if it's the best Idea to store all the data in the model.
What benefits are there if all the data is stored in Objects (in an ArrayList for example) and the model only shows the data from the objects of the list?
This came into my mind particularly after I need to write some sorting algorithms which would be way easier to handle on some kind of list. Also saving the "model" --> the list of objects (then) would be easier than saving a table model.
Is it more efficient to stay with my current concept (save data in model | serialize model to save table | sort model itself) or is it better to save everything in Objects each Object representing one row, which are stored in a list?
I need to write some sorting algorithms
JTable supports sorting of the data in the TableModel directly. Read the section from the Swing tutorial on Sorting and Filtering for more information. So this can be handled directly by the table so you don't need external code.
each Object representing one row, which are stored in a list?
Yes this is a valid approach, but the data must still reside in the TableModel. That is the List containing your custom Objects that represent a row in the table must be defined in the TableModel. If for some reason you need to access the List you add helper methods to the TableModel. Don't keep the data in two places.
For example, check out Row Table Model which was designed for this concept. The JButtonTableModel.java code shows what you would need to code for each custom object you want to store in a table.
I created a database, in which one of the table name is Location which has 2 columns named Stadium and City. I want that data in each column should get retrieved in 2 JList, but I don't know how. Can you guys tell me how to do it?
The normal way to display a table from a database is of course a JTable. But if you want to opt for 2 JLists instead, it is basically the same principle.
Create a model based on the contents of the database (in this case a ListModel). You can probably just extend from AbstractListModel. Once you have your model, it is trivial to create a JList for it by just passing the model in the constructor.
See the How to use lists tutorial and pay special attention on the Creating a model part of that tutorial
I have a problem for a couple of hours does not resolve, is the following.
I have a Table A and Table B.
Table A is filled with a ResultSet, and Table B is being added to products available in Table A
What I am trying to achieve is: Once you click on the Add button Spend the product of Table A to Table B, and the last product is no longer displayed in Table A.
The responsibility to inform the tables that data was added and remove to and from them is completely up to you, and should be handled in each table's model. If you want to 'move' data from one to the other, you need to remove that data from the model of the first table and add it to the 2nd. Once that is done, both models need to be informed of the change via fireTableDataChanged, so they know to redraw.
I would endorse #Colby's and #GETah's suggestion to focus on the model. Also consider giving modelA and modelB access to a common data structure, say List<Product>, where each Product has a boolean attribute that allows each model to to decide what it's corresponding view can see.
Get and remove the selected element from tableA's TableModel and add it to the tableB's TableModel and then refresh both tables.
See this tutorial on using JTable and TableModel
I display a list of db table rows which are editable. I would like to allow users to edit the data in the displayed table and save all updates at the same time. How should I get back the list of updates to the controller?
As Play can bind to POJO's and also bind to Lists, it should be possible to simply create a list of POJOs.
See here for more details http://www.playframework.org/documentation/1.2.2/controllers#array.
It does not give this as an explicit example, but it should work.
If it does not, then the other options you have is to create your own custom binder (also described on the page linked to above).