Skip to content

Sample 007

Michael Karneim edited this page May 9, 2018 · 1 revision
package wiki.snippets;

import java.awt.FlowLayout;

import javax.swing.JFrame;

import org.beanfabrics.model.TextPM;
import org.beanfabrics.model.ITextPM;
import org.beanfabrics.swing.BnTextField;

/**
 * Sample for using a BnTextField
 */
public class Sample007 {
    public static void main(String[] args) {
        // create a textfield
        BnTextField textfield = new BnTextField();
        textfield.setColumns(20);
        
        // the BnTextField is a View on a ITextPM
        // Let's create a model
        ITextPM model = new TextPM();
        // set some text
        model.setText("Hello, you can edit me!");
        
        
        // bind the textfield to the model directly
        textfield.setPresentationModel(model);
        
        // show the textfield inside a frame
        JFrame frame = new JFrame("Using BnTextField");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLayout( new FlowLayout());
        frame.add(textfield);
        frame.setSize(300, 300);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}
Clone this wiki locally