开发者

How do I Bind a Collection (ArrayList) returned by a Web Service to JTable in Swing?

开发者 https://www.devze.com 2022-12-09 11:09 出处:网络
I am developing a business application in .NET and Java. In .NET I have developed a web-service which uses basicHttpBinding. I am consuming this web-service in a Java client. The web-service is workin

I am developing a business application in .NET and Java. In .NET I have developed a web-service which uses basicHttpBinding. I am consuming this web-service in a Java client. The web-service is working fine, calling it in the Java code returns an ArrayList collection of Holding class. This class is described below:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Holding", propOrder = {
    "companyName",
    "price",
    "quantity",
    "scripCode"
})
public class Holding {

    @XmlElementRef(
        name = "CompanyName", 
        namespace = "http://schemas.datacontract.org/2004/07/JavaLIB", 
        type = JAXBElement.class)
    protected JAXBElement<String> companyName;

    @XmlElementRef(
        name = "Price", 
        namespace = "http://schemas.datacontract.org/2004/07/JavaLIB", 
        type = JAXBElement.class)
    protected JAXBElement<String> price;

    @XmlElementRef(
        name = "Quantity", 
        namespace = "http://schemas.datacontract.org/2004/07/JavaLIB", 
        type = JAXBElement.class)
    protected JAXBElement<String> quantity;

    @XmlElement(name = "ScripCode")
    protected Integer scripC开发者_如何转开发ode;

    /**
     * Gets the value of the companyName property.
     * 
     * @return
     *     possible object is
     *     {@link JAXBElement }{@code <}{@link String }{@code >}
     *     
     */
    public JAXBElement<String> getCompanyName() {
        return companyName;
    }

    /**
     * Sets the value of the companyName property.
     * 
     * @param value
     *     allowed object is
     *     {@link JAXBElement }{@code <}{@link String }{@code >}
     *     
     */
    public void setCompanyName(JAXBElement<String> value) {
        this.companyName = ((JAXBElement<String> ) value);
    }

    /**
     * Gets the value of the price property.
     * 
     * @return
     *     possible object is
     *     {@link JAXBElement }{@code <}{@link String }{@code >}
     *     
     */
    public JAXBElement<String> getPrice() {
        return price;
    }

    /**
     * Sets the value of the price property.
     * 
     * @param value
     *     allowed object is
     *     {@link JAXBElement }{@code <}{@link String }{@code >}
     *     
     */
    public void setPrice(JAXBElement<String> value) {
        this.price = ((JAXBElement<String> ) value);
    }

    /**
     * Gets the value of the quantity property.
     * 
     * @return
     *     possible object is
     *     {@link JAXBElement }{@code <}{@link String }{@code >}
     *     
     */
    public JAXBElement<String> getQuantity() {
        return quantity;
    }

    /**
     * Sets the value of the quantity property.
     * 
     * @param value
     *     allowed object is
     *     {@link JAXBElement }{@code <}{@link String }{@code >}
     *     
     */
    public void setQuantity(JAXBElement<String> value) {
        this.quantity = ((JAXBElement<String> ) value);
    }

    /**
     * Gets the value of the scripCode property.
     * 
     * @return
     *     possible object is
     *     {@link Integer }
     *     
     */
    public Integer getScripCode() {
        return scripCode;
    }

    /**
     * Sets the value of the scripCode property.
     * 
     * @param value
     *     allowed object is
     *     {@link Integer }
     *     
     */
    public void setScripCode(Integer value) {
        this.scripCode = value;
    }

}

My problem is that I don't know how to bind these ArrayList<Holding> to a JTable - I have not worked much on Swing.

If someone can provide a link to a good tutorial (other than the one on the Sun website - I have seen that) or can quickly guide me how to implement a TableModel class for it that would be great.

I also have to get data from web-service after each 5 second interval, so please also provide a tutorial describing how to re-bind.


I guess this tutorial from Sun is what you need. You will find what you need to build directly the JTable containing your data. Some paragraphs later you can also find how to build a TableModel.

Enjoy!


If someone can quickly guide me how to implement a TableModel class for it that would be great.

Check out the BeanTableModel entry. Although I doubt you will be able to use the BeanTableModel because of the JAXBElement code, you should be able to use the JButtonTableModel example which shows you how to extend my RowTableModel to create your custom model.

0

精彩评论

暂无评论...
验证码 换一张
取 消