开发者

JCheckbox in Java swing

I have created one checkbox this way:

JCheckbox field = new JCheckBox("EDEX:", true);.

I was add this to Jpan开发者_如何学运维el and layout is FormLayout using CellConstraints xy positions.

but it is not displayed EDEX text after checkbox.

this is code:

panel.add(field , cc.xy(5, 3));

please help me

Thank You


This works fine:

JCheckbox in Java swing

import java.awt.EventQueue;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;

import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class Example {

    public Example() {
        FormLayout layout =
            new FormLayout( "left:pref, 15px, center:pref, 15px, right:pref, 15px, fill:pref, 15px, pref",
                            "pref, 12px, pref, 4px, pref, 4px, pref, 4px, pref, 4px, pref" );

        JPanel panel = new JPanel( layout );
        CellConstraints cc = new CellConstraints();

        JCheckBox field = new JCheckBox( "EDEX:", true );
        panel.add( field, cc.xy( 5, 3 ) );

        JFrame f = new JFrame();
        f.setBounds( 10, 10, 100, 100 );
        f.setDefaultCloseOperation( 3 );
        f.getContentPane().add( panel );
        f.setVisible( true );
    }

    public static void main( String[] args ) {
        EventQueue.invokeLater( new Runnable() {
            @Override
            public void run() {
                new Example();
            }
        } );
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜