# 3
Robert,
As I said before, the first tutorial shows a step by step for creating your own data provider. I acknowledged that this was for an array of data that comes from a database, but you can apply the knowledge to any ArrayList.
I then pointed you to the sample project that binds the data provider to an array of JavaBean objects. That is what you said you wanted to do. The JavaBean provides the 3rd dimension (the columns). So I will bring the mountain to you and post the code for the custom data provider. In this sample, I hard code the JavaBean objects but I assume you would know how to modify the code to fill it up with your data. If you want to know what the table looks like or what the JavaBean class looks like, go to the blog.
import com.sun.data.provider.impl.ObjectListDataProvider;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author localuser
*/
public class FoodListDataProvider extends ObjectListDataProvider{
private List foodList = new ArrayList();
/** Creates a new instance of foodListDataProvider */
public FoodListDataProvider() {
foodList.add(new FoodItem("20100", "2000", "macaroni, cooked",
"Macaroni, cooked, enriched",
'Y', 0, "", 45, 21, 81, 5, 14
));
foodList.add(new FoodItem("20345", "2000", "rice, white",
"Rice, white, long-grain, regular, cooked, enriched, with salt",
'Y', 0, "", 194, 35, 88, 3, 9));
foodList.add(new FoodItem("11027", "1100", "bamboo shoots",
"Bamboo shoots, cooked, boiled, drained, without salt",
'N', 0, "", 25, 5, 60, 18, 22));
foodList.add(new FoodItem("11053","1100", "beans, green",
"Beans, snap, green, cooked, boiled, drained, without salt",
'Y', 0, "", 44, 10, 80, 7, 13));
foodList.add(new FoodItem("11109", "1100", "cabbage, raw",
"Cabbage, raw",
'Y', 20, "Brassica oleracea (Capitata Group)", 21, 7, 81, 4, 15));
foodList.add(new FoodItem("11091", "1100", "broccoli, cooked",
"Broccoli, cooked, boiled, drained, without salt",
'Y', 0, "", 44, 8, 64, 10, 26));
foodList.add(new FoodItem("11124","1100","carrots, raw",
"Carrots, raw",
'Y', 11, "Daucus carota", 52, 12, 89, 5, 6));
foodList.add(new FoodItem("09003","0900","apples, raw",
"Apples, raw, with skin",
'Y', 8, "Malus domestica", 65, 15, 95, 3, 2));
foodList.add(new FoodItem("09037","0900", "avocados, raw",
"Avocados, raw, all commercial varieties",
'Y', 26, "Persea americana", 240, 45, 19,77, 4));
foodList.add(new FoodItem("09040","0900", "bananas, raw",
"Bananas, raw",
'Y', 36, "Musa X paradisiaca", 200, 25, 93, 3, 4));
foodList.add(new FoodItem("09063","0900","cherries",
"Cherries, sour, red, raw",
'Y',10,"Prunus cerasus", 77, 14, 88, 5, 7));
foodList.add(new FoodItem("12061","1200","almonds",
"Nuts, almonds",
'Y',0,"Prunus dulcis",54,163,14,73,13));
foodList.add(new FoodItem("12131","1200","macadamia nuts",
"Nuts, macadamia nuts, raw",
'N',69,"Macadamia integrifolia, M. tetraphylla",952,203,8,88,4));
foodList.add(new FoodItem("12155","1200","walnuts",
"Nuts, walnuts, english",
'Y',55,"Juglans regia",765, 185, 9, 83, 8));
foodList.add(new FoodItem("04581","0400","avocado oil",
"Vegetable oil, avocado",
'N',0,"",1927, 250, 0, 100, 2));
this.setList(foodList);
}
}
Hope this helps,
Chris