|
How to populate a JTable
Here are the results
As we can see we got a load of data Modeltable Persona, and we discard the column named id
To load data into an object javax.swing and very simple, the logic generated by WritePojo provides a class called Configuration, the Configuration and configure a class devoted to each object created from the transcript made by our DB if we have a user table, Write create a User class with the appropriate set and get methods, this article reviews will be used by us for simple operations, rescue data, editing and deleting data from our DB. Through these objects, we can instruct the Configuration class to receive in exchange a custom search, a list of objects, a DefaulMoeltable a DefaulModelComboBox, and DefaulModelList in this class and more able to configure custom objects from ourselves .. We begin to see and what DefaultModelTable accepts. we see that the first method accepts a list of items .. Configuration.modelTable (List list); the second takes two parameters a list of objects and an array of String with which we define which columns to hide a custom table Configuration.modelTable (List list, String [] fieldNamedHidden); in the third takes a ResaultSet Configuration.modelTable (ResultSet rs); and the fourth as the second takes two parameters, a resault September and an entire column in which we define to hide. Configuration.modelTable (ResultSet rs, int hidden); This allows us both to hide the column, and receive a value the column indicating, for example, if we can retrieve the id hide from our model with the proper method getObj (JTable); Configuration.modelTable (ResultSet rs, int hidden, String idcolumn); Now we see how to receive a JTable load user data ..
We begin to see and what to accept DefaultModelTable. Now we see how to receive a JTable load user data ..
1)º
Here
Here are the results
As we can see we got a load of data ModelList Persona, and we see only the name and surname
Here are the results
As we can see we got a load of data ModelComboBox Persona, and we see only the name and surname
How to Obtain the user ID of our operations
The DefaultModelTable the DefaultModelList, and DefaultModelComboBox all contain two methods that return
developed in our case the object and user object, taken this subject will find all the methods
associated with it, then we will also have the method getId (); that returns the id ..
we should not see a row like so many strings, but as a user object, then selecting the row will
Our method with a user.
This technique is much better when you consider how many benefits it brings because thanks to the built-in logic, we received with the subject
We can make various changes without worrying about finding them, we can edit it, save, and delete it without creating other methods ..
DefaultModelList Example how to obtain the object from DefaultModelList Utente utente=(Utente)model.getObj(jList1); Utente utente=(Utente)model.getObjectAtID(Object item); The methods that return an object of class 2 are DefaultModelList getObj (JList jlist) and getObjectAtID (Object item) We note the method getObjgetObj (JList jlist) takes a JList and he will take care of extracting the selected object, while the other method getObjectAtID (Object item); takes a value of the item selected, In this case we will provide value to the item selected. DefaultModelComboBox Example how to obtain the object from DefaultModelComboBox Utente utente=(Utente)model.getObj(jComboBox); Utente utente=(Utente)model.getObjectAtID(Object item); The methods that return an object of class 2 are DefaultModelComboBox getObj (JList jlist) and getObjectAtID (Object item) We note the method getObjgetObj (JComboBox JComboBox) takes a JComboBox and he will take care of extracting the selected object, while the other method getObjectAtID (Object item); takes a value of the item selected, In this case we will provide value to the item selected. |
||||||
|
|||||||