« Return to Thread: Netbeans Bean Binding - BindingGroup

Re: Netbeans Bean Binding - BindingGroup

by Jiri Vagner :: Rate this Message:

Reply to Author | View in Thread

Hi!
So you want to use jtable binding to fill jtable content withou wizards.
Did I understand it correctly?

Small example:

 - add Car class to your project

public class Car {
    private String manufacturer;
    private String model;

    public String getManufacturer() {
        return manufacturer;
    }
    public void setManufacturer(String manufacturer) {
        this.manufacturer = manufacturer;
    }
    public String getModel() {
        return model;
    }
    public void setModel(String model) {
        this.model = model;
    }
}


 - add bean property to your form

public class YourFrame extends javax.swing.JFrame {
    private List<Car> _cars = new ArrayList<Car>();

    public void setCarList(List<Car> cars) {
        _cars = cars;
    }
    public List<Car> getCarList() {
        if (_cars.isEmpty()) {
            Car car =new Car();
            car.setManufacturer("Lancia");
            car.setModel("Lybra");
            _cars.add(car);

            car = new Car();
            car.setManufacturer("Lancia");
            car.setModel("Thesis");
            _cars.add(car);
        }
        return _cars;
    }
.....

- select jTable and invoke bind dialog  Bind -> elements
- as Binding source set Form
- as Binding expression tree select node "carList java.util.List" or
just type  "${carList}"
- select fields to display
- run the form

Hope it helps.
Jirka Vagner


jasonwpalmer wrote:

> Has anyone experienced problems with auto-generated beans binding wizard in
> Netbeans 6.5 (SWING) ? I have done a lot of Web Applications and am learning
> SWING. I might even learn quicker if I could learn how to code this
> manually, but many tutorials are written using the Wizards that Netbeans
> offers and when I have problems it is hard to pinpoint problems in
> auto-generated code!
>
> When I drop a table on the page in the Visual Designer and try to setup the
> binding by right-clicking and selecting bind-->elements. I use a List that
> is populated in Constructor of JFrame with JPA that holds a List of Entity
> Beans. I know that the List is populated with Entities and Persistence.xml
> is all in order and functioning correctly.
>
> Everytime the GUI is displayed it shows an empty table with default values
> defined in TableModel. Also when the Wizard completes in Visual Designer at
> Design Time - the table appears unchanged even though the Binding Wizard
> seems to have completed successfully.
>
> I understand that I can extend AbstractTableModel and provide a concrete
> implementation and just bind the table appropriately. This seems to be alot
> of work and I would like to use JSR 295 BeansBinding instead.
>
> Does anyone have a similiar problem that they have overcome?
>
> Jason Palmer
>  

 « Return to Thread: Netbeans Bean Binding - BindingGroup