http://oldsite.linuxaid.com.cn/developer/showdev.jsp?i=483
这是讲而已的,看看!!

解决方案 »

  1.   

    to icystone:
      实际运行若写成0,就跑到旁边去了。
      

  2.   

    /**
       @version 1.30 2000-05-12
       @author Cay Horstmann
    */import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;public class FontDialog
    {
       public static void main(String[] args)
       {  
          FontDialogFrame frame = new FontDialogFrame();
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.show();
       }
    }/**
       A frame that uses a grid bag layout to arrange font
       selection components.
    */
    class FontDialogFrame extends JFrame
    {  
       public FontDialogFrame()
       {  
          setTitle("FontDialog");
          setSize(WIDTH, HEIGHT);      Container contentPane = getContentPane();
          GridBagLayout layout = new GridBagLayout();
          contentPane.setLayout(layout);      ActionListener listener = new FontAction();      // construct components
          
          JLabel faceLabel = new JLabel("Face: ");      face = new JComboBox(new String[] 
             {  
                "Serif", "SansSerif", "Monospaced", 
                "Dialog", "DialogInput" 
             });
          
          face.addActionListener(listener);      JLabel sizeLabel = new JLabel("Size: ");      size = new JComboBox(new String[]
             {
                "8", "10", "12", "15", "18", "24", "36", "48"
             });      size.addActionListener(listener);      bold = new JCheckBox("Bold");
          bold.addActionListener(listener);      italic = new JCheckBox("Italic");
          italic.addActionListener(listener);      sample = new JTextArea();
          sample.setText(
             "The quick brown fox jumps over the lazy dog");
          sample.setEditable(false);
          sample.setLineWrap(true);
          sample.setBorder(BorderFactory.createEtchedBorder());      // add components to grid      GridBagConstraints constraints = new GridBagConstraints();      constraints.fill = GridBagConstraints.NONE;
          constraints.anchor = GridBagConstraints.EAST;
          constraints.weightx = 0;
          constraints.weighty = 0;      add(faceLabel, constraints, 0, 0, 1, 1);
          add(sizeLabel, constraints, 0, 1, 1, 1);      constraints.fill = GridBagConstraints.HORIZONTAL;
          constraints.weightx = 100;
          
          add(face, constraints, 1, 0, 1, 1);
          add(size, constraints, 1, 1, 1, 1);      constraints.weighty = 100;
          constraints.fill = GridBagConstraints.NONE;
          constraints.anchor = GridBagConstraints.CENTER;      add(bold, constraints, 0, 2, 2, 1);//这里要是改成 1,2,2,1,就会错位
          add(italic, constraints, 0, 3, 2, 1);      constraints.fill = GridBagConstraints.BOTH;
          add(sample, constraints, 2, 0, 1, 4);
       }
      
       /**
          A convenience method to add a component to given grid bag
          layout locations.
          @param c the component to add
          @param constraints the grid bag constraints to use
          @param x the x grid position
          @param y the y grid position
          @param w the grid width
          @param h the grid height
       */
       public void add(Component c, GridBagConstraints constraints,
          int x, int y, int w, int h)
       {  
          constraints.gridx = x;
          constraints.gridy = y;
          constraints.gridwidth = w;
          constraints.gridheight = h;
          getContentPane().add(c, constraints);
       }   public static final int WIDTH = 300;
       public static final int HEIGHT = 200;     private JComboBox face;
       private JComboBox size;
       private JCheckBox bold;
       private JCheckBox italic;
       private JTextArea sample;   /**
          An action listener that changes the font of the 
          sample text.
       */
       private class FontAction implements ActionListener
       {
          public void actionPerformed(ActionEvent event)
          {  
             String fontFace = (String)face.getSelectedItem();
             int fontStyle = (bold.isSelected() ? Font.BOLD : 0)
                + (italic.isSelected() ? Font.ITALIC : 0);
             int fontSize = Integer.parseInt(
                (String)size.getSelectedItem());
             Font font = new Font(fontFace, fontStyle, fontSize);
             sample.setFont(font);
             sample.repaint();
          }
       }
    }
      

  3.   

    UP~~~~~~~~
    ----------------------
    《CSDN论坛新助手 CSDN's forum Explorer》
    1、更快速的浏览
    2、更方便地保存
    3、更快捷的收/发短信
    下载地址:http://www.seeyou.com.cn/CoolSlob/CSDNExplorer.exe
    更多说明:http://community.csdn.net/Expert/TopicView.asp?id=3255966
      

  4.   

    这个布局gridx=0,grid=2
    表示没有行限制,只能有两列
      

  5.   

    怎么能没有限制呢,明明是有限制的,而且gridx定义的是列的位置,gridy才是行的位置,楼上的搞反了