说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

请问GridBagConstraints(有源码)

编辑:说三道四文库 发布时间:2018-06-23 05:16
HTML文档下载 WORD文档下载 PDF文档下载
有没有合适的例子?
            final JScrollPane scrollPane = new JScrollPane(table);
            int width = scrollPane.WIDTH;
            int height = scrollPane.HEIGHT;
            //Add the scroll pane to this window.
  
            GridBagLayout layout = new GridBagLayout();
            getContentPane().setLayout(layout);
            
            GridBagConstraints con1 =new GridBagConstraints();
            con1.weightx=100;
            con1.weighty=100;
            con1.gridx =0;
            con1.gridy =0;
            con1.gridwidth = width;
            con1.gridheight =height-150;
            con1.anchor=GridBagConstraints.NORTHEAST;
            con1.fill =GridBagConstraints.BOTH;
            getContentPane().add(scrollPane,con1);
             
          //  getContentPane().add(scrollPane, BorderLayout.CENTER);

            
            JButton next = new JButton("下一步");
            next.setBounds(width-150,height-200,100,25);
            
            GridBagConstraints con2 =new GridBagConstraints();
            con2.weightx=0;
            con2.weighty=0;
            con2.gridx =50;
            con2.gridy =height-100;
            con2.gridwidth = 50;
            con2.gridheight =25;
         //   con2.fill = GridBagConstraints.NONE;
         //  con2.anchor =GridBagConstraints.NONE;
           // con1.anchor=GridBagConstraints.;
          //  con1.fill =GridBagConstraints.HORIZONTAL;
           getContentPane().add(next,con2);
            
            JButton back = new JButton("上一步");
            back.setBounds(width-250,height-200,100,25);
    //        getContentPane().add(back,BorderLayout.LINE_END);  
            GridBagConstraints con3 =new GridBagConstraints();
            con3.weightx=0;
            con3.weighty=0;
            con3.gridx =0;
            con3.gridy =height-100;
            con3.gridwidth = 50;
            con3.gridheight =25;  
        //    con3.fill =GridBagConstraints.NONE;
         //   con3.anchor = GridBagConstraints.NONE;
            getContentPane().add(back,con3);

如上例子!我想把表格放在屏幕的上方
button只是放在屏幕的最下面(同行,且有一定的间距)

但是怎么尝试都没达到理想效果!哪位用过的提示一下!


找个GUI编辑的IDE看看就行了,光用代码太累了。NetBean或者jbuilder
备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn 说三道四技术文摘