Skip to content

rickyclarkson/fj-swing

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 

Repository files navigation

fj-swing attempts to provide bindings between mutable values and Swing components. For example:

final Value<String> text = new Value<String>("Enter a number");
frame.getContentPane().add(TextFieldW.textField(new JTextField(20)).bind(text).unwrap());

This creates a mutable value, 'text', and binds a JTextField to it. Whenever the user changes the JTextField, the value in text changes, and vice versa.

final ValueView<Boolean> isANumber = text.map(new F<String, Boolean>() {
    @Override
    public Boolean f(String s) {
        try {
            Integer.parseInt(s);
            return true;
        } catch (NumberFormatException ignored) {
            return false;
        }
    }
});

This creates a view of the first value, and that view reads as true when the original value (and hence, the text field) contains a value that can be parsed to an int.

frame.getContentPane().add(button("Well done").bind(visibility, isANumber).unwrap());

This creates a button that is only visible when isANumber reads as true. A runnable version of this example can be found in Example1.java

About

Bindings between mutable values and Swing components

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages