Download
As a Mapping Database with Write Pojo
Save - Edit - Delete
Configure List - Object - Filtered
How to populate a JTable, JList, JComboBox
How to Change Parameters for the connection to our database
Contact

How to populate a JTable
List<Persona> list = Configuration.configure(Persona.CLASS_NAME);
DefaultModelTable model = Configuration.modelTable(list, new String[]{"id"});
jTable1.setModel(model);

Here are the results

As we can see we got a load of data Modeltable Persona, and we discard the column named id
Configuration.modelTable(list, new String[]{"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.
we see that the first method accepts a list of objects
..
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 ..

1)º
Users will need a list to feed to this class,
for we will always quickly find the Configuration class.
Here's how:


List<Utente> utenti = Configuration.configure(Utente.CLASS_NAME);

Users now have list full of data, we can only give it as food
our Configuration, to receive a ModelTable a Modelling, ModelComboBox a load of data.

Example:

DefaultModelTable model = Configuration.modelTable(utenti);
jTable.setModel(model);


with only three lines of code we received a list of office data
JTable and a preloaded, and all this without worrying about making
calls to our DB, not bothering to close the connections
and without worrying about cycling items ..

Here
List<Persona> list = Configuration.configure(Persona.CLASS_NAME);
DefaultModelTable model = Configuration.modelTable(list, new String[]{"id"});
jTable1.setModel(model);



As we can see we got a load of data Modeltable Persona, and we discard the column named id
Configuration.modelTable(list, new String[]{"id"});



JList

How to populate a JList
List<Persona> list = Configuration.configure(Persona.CLASS_NAME);
DefaultModelList model = Configuration.modelList(list, new String[]{"nome", "cognome"});
jList.setModel(model);

Here are the results

As we can see we got a load of data ModelList Persona, and we see only the name and surname
Configuration.modelList(list, new String[]{"nome", "cognome"});




JComboBox

How to populate a JComboBox
List<Persona> list = Configuration.configure(Persona.CLASS_NAME);
DefaultModelComboBox model = Configuration.modelComboBox(list, new String[]{"nome", "cognome"});
jList.setModel(model);

Here are the results

As we can see we got a load of data ModelComboBox Persona, and we see only the name and surname
Configuration.modelComboBox(list, new String[]{"nome", "cognome"});


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 ..


DefaultModelTable
Example how to obtain the object from DefaultModelTable
Utente utente=(Utente)model.getObj(jTable1);
Utente utente=(Utente)model.getObjectAtID(int row);

The methods that return an object of class 2 are DefaultModelTable getObj (JTable JTable) and getObjectAtID (int row)
We note the method getObj (JTable JTable) takes a JTable and he will take care of extracting the selected object,
while the other method getObjectAtID (int row); takes an int for the selected row,
quiet stand in the case we will then provide the selected row of the int.





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.












contatore