2013-05-27 146 views

回答

0

我還以爲這一小段代碼,可以幫助你出來......我做了它的淨咖啡豆,但我都談到了U中的重要組成部分....如果ü可以更具體關於「組織」,我可以幫你出來......但AFAIK..if你的意思是組織爲讓他們一組......那麼你知道它很容易將它們分組和u還可以使用一個for循環來標註全部按鍵...;)...如果有別的讓我知道......我還一直在關注許多關於layout..so輸出佈局的尺寸必須小,但我敢肯定,U可以設置其大小;)歡呼!

import java.awt.*; 
import javax.swing.*; 

public class GridLayoutJRB { 
public final static boolean RIGHT_TO_LEFT = false; 

public static void addComponentsToPane(Container contentPane) { 
    if (RIGHT_TO_LEFT) { // blah ! blah ! blah ! 
     contentPane.setComponentOrientation(
      ComponentOrientation.RIGHT_TO_LEFT); 
    } 
//  3 rows and 3 columns..this is what you require here .. :) 
    contentPane.setLayout(new GridLayout(3,3)); 

    contentPane.add(new JRadioButton("1")); 
    contentPane.add(new JRadioButton("2")); 
    contentPane.add(new JRadioButton("3")); 
    contentPane.add(new JRadioButton("4")); 
    contentPane.add(new JRadioButton("5")); 
    contentPane.add(new JRadioButton("6")); 
    contentPane.add(new JRadioButton("7")); 
    contentPane.add(new JRadioButton("8")); 
    contentPane.add(new JRadioButton("9")); 
} 
//again blah blah blah ! 
private static void createAndShowGUI() { 
    JFrame.setDefaultLookAndFeelDecorated(true); 

    JFrame frame = new JFrame("GridLayout With JRadio Buttons"); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

    //Set up the content pane and components in GridLayout 
    addComponentsToPane(frame.getContentPane()); 

    frame.pack(); 
    frame.setVisible(true); 
} 

public static void main(String[] args) { 
    javax.swing.SwingUtilities.invokeLater(new Runnable() { 
     @Override 
     public void run() { 
      createAndShowGUI(); 
     } 
    }); 
} 
} 
+0

,是的它的網格佈局:d – uLYsseus