2011-09-02 95 views
-1

我已創建了一個複選框,這樣說:JCheckBox的在Java中搖擺

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

我將它添加到JPanel並佈局的FormLayout使用CellConstraints XY位置。

但在複選框後不顯示EDEX文本。

這是代碼:

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

請幫我

謝謝

+1

告訴我們有關'CC更多的代碼',w沒有它工作正常。 btw:'JCheckBox'而不是'JCheckbox' – oliholz

回答

2

這工作得很好:

enter image description here

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

不錯的截圖,但要製作一個*很棒的截圖,請查看關於[如何創建截圖?]的提示(http://meta.stackexchange.com/questions/99734 /怎麼辦,我創建-A-截圖到說明-A-後)。 –