How do i bind a jtextfield to get text from the database in Netbeans?
开发者_如何转开发I can't seem to find any information on binding the text of a Jtextfield to data from a database in Netbeans 6. Is it just tables that can be bound?
I don't think there is a way to actually bind textfields effectively to a JPA entity.
My Discovery: I discovered you can drag an entity manager and a query on to GUI designer and configure them to work with each other. But you can't bind the query to the textfield. What you want to do, is bind your persistence entity to the Textfield. So, add your entity to the palette.
You have to right-click the netbeans palette and go to palette manager->add from project. Select your project and you will be able to add all your persistence entities to the palette (best create a new folder for them). You should now have your entities in the palette. drag onto screen as usual and assign query to entity.
Yo can now open up properties of a textfield-> binding tab and bind the TEXT property of the textfield to your entity and then select which "column" from that entity you truly wish to bind text to. This should should be bound now and would work for most cases.
HOWEVER, In an application were that entity needs to be changed often, it is useless because the binding to the textfield does not update itself. So it essentially only acts "bound" that first time. This is mainly because when you change an entity, it's really a different memory object at that point.
e.g clientEntity = (Query) clientQuery.getSingleResult();
I believe it's safe to say that Swing has been abandoned when it comes to entity binding as JPA and entities in their current state is only really useful with "session" based web services where you typically would be the one to set/get entity column values and merge when done.
精彩评论