本帖最后由 douzhiwt 于 2011-08-10 14:16:18 编辑

解决方案 »

  1.   

    import java.awt.*;
    import javax.swing.*;public class zb3 extends javax.swing.JFrame {   /** Creates new form zb */
       public zb3() {
           initComponents();
           ms();
       }
       private void ms(){
           jpAll=new JPanel();
           jpAll.setSize(100,100);
           jpAll.setLayout(new GridLayout(4, 1));
           jScrollPane1.add(jpAll);       JButton jb = new JButton("aaa");
           jb.setPreferredSize(new Dimension(100, 200));
           jpAll.add(jb);       JButton jb2 = new JButton("bbbb");
     
           jpAll.add(jb2);       JButton jb3 = new JButton("ccccccc");       jpAll.add(jb3);       JButton jb4 = new JButton("Ddddd");       jpAll.add(jb4);
           jpAll.show();
       }   /** This method is called from within the constructor to
        * initialize the form.
        * WARNING: Do NOT modify this code. The content of this method is
        * always regenerated by the Form Editor.
        */
       @SuppressWarnings("unchecked")
       // <editor-fold defaultstate="collapsed" desc="Generated Code">
       private void initComponents() {       jScrollPane1 = new javax.swing.JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
           jlbTitle1 = new javax.swing.JLabel();
           jlbTishi = new javax.swing.JLabel();
           jlbTitle2 = new javax.swing.JLabel();       setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);       jScrollPane1.setName("jScrollPane1"); // NOI18N
           jScrollPane1.getViewport().setBackground(Color.red);
           jScrollPane1.setVerticalScrollBar(new JScrollBar());       jlbTitle1.setText("版号版名");
           jlbTitle1.setName("jlbTitle1"); // NOI18N       jlbTishi.setText("提示信息");
           jlbTishi.setName("jlbTishi"); // NOI18N       jlbTitle2.setText("版号版名");
           jlbTitle2.setName("jlbTitle2"); // NOI18N       javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
           getContentPane().setLayout(layout);
           layout.setHorizontalGroup(
               layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(layout.createSequentialGroup()
                   .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                       .addGroup(layout.createSequentialGroup()
                           .addGap(79, 79, 79)
                           .addComponent(jlbTitle2, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                           .addGap(131, 131, 131)
                           .addComponent(jlbTishi)
                           .addGap(143, 143, 143)
                           .addComponent(jlbTitle1, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE))
                       .addGroup(layout.createSequentialGroup()
                           .addContainerGap()
                           .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE)))
                   .addContainerGap())
           );
           layout.setVerticalGroup(
               layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(layout.createSequentialGroup()
                   .addContainerGap()
                   .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                       .addComponent(jlbTitle2)
                       .addComponent(jlbTishi)
                       .addComponent(jlbTitle1))
                   .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                   .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 306, Short.MAX_VALUE)
                   .addContainerGap())
           );       pack();
       }// </editor-fold>   /**
       * @param args the command line arguments
       */
       public static void main(String args[]) {
           java.awt.EventQueue.invokeLater(new Runnable() {
               public void run() {
                   new zb3().setVisible(true);
                   
               }
           });
       }   // Variables declaration - do not modify
       private javax.swing.JScrollPane jScrollPane1;
       private javax.swing.JLabel jlbTishi;
       private javax.swing.JLabel jlbTitle1;
       private javax.swing.JLabel jlbTitle2;
       // End of variables declaration
       private javax.swing.JPanel jpAll;
    }