简体   繁体   中英

Populate swing JTable with Backendless data

I'm working in android/desktop application using backendless to share data between my PC and my Android device.

I've created a class in backendlass which contains 2 columns "Name" "Url" (both are strings)

I want to retrieve the data of this class in a JTable, but I don't know how to start that

So I found the answer by myself, I'm writing the code here if someone else need it :

Let's say you have a contact object with a name and phonenumber (both strings) and you want to show them on a JTable retrieving the name and the number from backendless :

public void retrieveInformation(BackendlessDataQuery query,final DefaultTableModel model){
    System.out.println("Retrieving Data...");
    Backendless.Data.of(Contact.class).find(query, new AsyncCallback<BackendlessCollection<Contact>>() {

        @Override
        public void handleResponse(BackendlessCollection<Contact> backendlessCollection) {


             Object[] row = new Object[2];
             for (Contact map : backendlessCollection.getCurrentPage()){
                 row[0] = map.getName();
                 row[1] = map.getNumber();
                 model.addRow(row);
                 System.out.println("Retrieving Data complete !");
             }


        }

        @Override
        public void handleFault(BackendlessFault backendlessFault) {
            System.out.println(backendlessFault.getMessage());
        }
    });}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM