简体   繁体   中英

java class property binding to swing component

I'm coming from .net world, but I have to make a small GUI application in Java. I would like to achieve that I have a class with some properties and I want to bind the properties to swing components (textfield, combo box) on a JDialog, JFrame.

There are many threads in the net talking about this, but I was not able to achieve the stuff to be working on my case. I have a class with a property PropertyChangeSupport, and addPropertyChangeListener and removePropertyChangeListener methods. In the GUI I could bind the JTextField text attribute to the class instance property. the JDialog is implementing the PropertyChangeListener

but if I write something to the text box nothing is updating in the class property.

Can you point me a complete tutorial about this issue?

thanks!

"but if I write something to the text box nothing is updating in the class property."

You're probably going to want to implement a DocumentListener to listen for changes in the underlying document of the text field. Every time the document changes, for instance the typing in of a letter, a DocumentEvent will be fired. You can see How to Write a DocumentListener

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