Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6964553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:56:22+00:00 2026-05-27T15:56:22+00:00

I have a simple JFrame with several jtextfields inside, the text property of each

  • 0

I have a simple JFrame with several jtextfields inside, the text property of each jtextfield is bound with a field of an object through databinding (i used window builder to setup the binding), when the user change something on the JTextField the changes are automatically reflected to the bound object property, i have the needs that when the user press a JButton (Cancel Button) every changes done by the user will be discarded.

So i want that when the user start editing the field like a transaction will be started and depending on the user action (OK or Cancel Button) the transaction being Committed or RollBacked .

Is it possible with Swing Data Binding framework ? How ?

Here the code that initialize data bindings :

    /**
     * Data bindings initialization 
     */
    protected void initDataBindings() {
        //Title field
        BeanProperty<Script, String> scriptBeanProperty = BeanProperty.create("description");
        BeanProperty<JTextField, String> jTextFieldBeanProperty = BeanProperty.create("text");
        AutoBinding<Script, String, JTextField, String> autoBinding = Bindings.createAutoBinding(UpdateStrategy.READ_WRITE, script, scriptBeanProperty, textFieldName, jTextFieldBeanProperty, "ScriptTitleBinding");
        autoBinding.bind();
        //Id field 
        BeanProperty<Script, Long> scriptBeanProperty_1 = BeanProperty.create("id");
        BeanProperty<JLabel, String> jLabelBeanProperty = BeanProperty.create("text");
        AutoBinding<Script, Long, JLabel, String> autoBinding_1 = Bindings.createAutoBinding(UpdateStrategy.READ, script, scriptBeanProperty_1, labelScriptNo, jLabelBeanProperty, "ScriptIdBinding");
        autoBinding_1.bind();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T15:56:23+00:00Added an answer on May 27, 2026 at 3:56 pm

    nothing out off the box, you have to implement the buffering logic yourself. An example is in my swinglabs incubator section, look at the AlbumModel. Basically

    • the bean is Album
    • AlbumModel is a wrapper (aka: buffer) around the bean with the same properties as the wrapped: the view is bound to the properties of this wrapper
    • internally, it uses a read-once binding to the wrappee properties
    • in addition, the wrapper has a property “buffering” which is true once any of its buffered properties is different from the wrappee. In this state, the changes can be either committed or canceled

    Below is an excerpt of AlbumModel (nearly all minus validation) which might give you an idea. Note that BindingGroupBean is a slightly modified BindingGroup which maps internal state to a bean property “dirty” to allow binding of “buffering”. You can find it in the incubator as well as a complete application BAlbumBrowser (an implementation of Fowler’s classical example in terms of BeansBinding)

    /**
     * Buffered presentation model of Album. 
     * 
     */
    @SuppressWarnings("rawtypes")
    public class AlbumModel extends Album {
        @SuppressWarnings("unused")
        private static final Logger LOG = Logger.getLogger(AlbumModel.class
                .getName());
        private Album wrappee;
    
        private BindingGroupBean context;
        private boolean buffering;
    
        public AlbumModel() {
            super();
            initBinding();
        }
    
        @Action (enabledProperty = "buffering")
        public void apply() {
            if ((wrappee == null)) 
                return;
            context.saveAndNotify();
        }
    
        @Action (enabledProperty = "buffering")
        public void discard() {
            if (wrappee == null) return;
            context.unbind();
            context.bind();
        }
    
        private void initBinding() {
            initPropertyBindings();
            initBufferingControl();
        }
    
        private void initBufferingControl() {
            BindingGroup bufferingContext = new BindingGroup();
            // needs change-on-type in main binding to be effective
            bufferingContext.addBinding(Bindings.createAutoBinding(UpdateStrategy.READ, 
                    context, BeanProperty.create("dirty"), 
                    this, BeanProperty.create("buffering")));
            bufferingContext.bind();
        }
    
        /**
         * Buffer wrappee's properties to this.
         */
        private void initPropertyBindings() {
            context = new BindingGroupBean(true);
            context.addBinding(Bindings.createAutoBinding(UpdateStrategy.READ_ONCE,
                    wrappee, BeanProperty.create("artist"), 
                    this, BeanProperty.create("artist")));
            context.addBinding(Bindings.createAutoBinding(UpdateStrategy.READ_ONCE,
                    wrappee, BeanProperty.create("title"), 
                    this, BeanProperty.create("title")));
            // binding ... hmm .. was some problem with context cleanup 
            // still a problem in revised binding? Yes - because
            // it has the side-effect of changing the composer property
            // need to bind th composer later
            context.addBinding(Bindings.createAutoBinding(UpdateStrategy.READ_ONCE,
                     wrappee, BeanProperty.create("classical"), 
                     this, BeanProperty.create("classical")));
            context.addBinding(Bindings.createAutoBinding(UpdateStrategy.READ_ONCE,
                    wrappee, BeanProperty.create("composer"), 
                    this, BeanProperty.create("composer")));
            context.bind();
        }
    
        public void setAlbum(Album wrappee) {
            Object old = getAlbum();
            boolean oldEditEnabled = isEditEnabled();
            this.wrappee = wrappee;
            context.setSourceObject(wrappee);
            firePropertyChange("album", old, getAlbum());
            firePropertyChange("editEnabled", oldEditEnabled, isEditEnabled());
        }
    
        public boolean isEditEnabled() {
            return (wrappee != null); // && (wrappee != nullWrappee);
        }
    
    
        public boolean isComposerEnabled() {
            return isClassical();
        }
    
        /**
         * Overridden to fire a composerEnabled for the sake of the view.
         */
        @Override
        public void setClassical(boolean classical) {
            boolean old = isComposerEnabled();
            super.setClassical(classical);
            firePropertyChange("composerEnabled", old, isComposerEnabled());
        }
    
        public boolean isBuffering() {
            return buffering;
        }
    
        public void setBuffering(boolean buffering) {
            boolean old = isBuffering();
            this.buffering = buffering;
            firePropertyChange("buffering", old, isBuffering());
        } 
    
        /**
         * Public as an implementation artefact - binding cannot handle
         * write-only properrties? fixed in post-0.61
         * @return
         */
        public Album getAlbum() {
            return wrappee;
        }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically I have a JFrame for a simple text editor. The filename you're working
I have simple issue setting a two-way databinding of a checkbox in Silverlight 3.0.
I have created a simple JFrame with two labels, two fields and two buttons.
I have created a simple Java application which has a JFrame and few JButtons.
I have a simple drawing program, I set my Jframe's size with the following
I have simple regex \.*\ for me its says select everything between and ,
I have simple win service, that executes few tasks periodically. How should I pass
i have simple regular expression: ^123$ Matches are for example 123 1234 etc. How
I have simple form. <form target=_blank action=somescript.php method=Post id=simpleForm> <input type=hidden name=url value=http://...> <input
I have simple SSIS package which reads data from flat file and insert into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.