java GridBagLayout 布局 速度急等很简单的
帮我写一个GridBagLayout布局3个控件jContentPane,jPane,jPane1要求不管Frame的大小怎么变jPane始终占据jContentPane...
帮我写一个GridBagLayout 布局
3个控件jContentPane,jPane,jPane1
要求不管Frame的大小怎么变
jPane始终占据jContentPane的1/3 用别的颜色标出来
jPane1始终占据jContentPane的1/3 用别的颜色标出来 展开
3个控件jContentPane,jPane,jPane1
要求不管Frame的大小怎么变
jPane始终占据jContentPane的1/3 用别的颜色标出来
jPane1始终占据jContentPane的1/3 用别的颜色标出来 展开
1个回答
展开全部
还有三分之一呢需要再加个panel。
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
public class test extends JFrame {
/**
* @param args
*/
public test(){
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setSize(400,300 );
JPanel jContentPane=new JPanel();
jContentPane.setBackground(Color.BLACK);
JPanel jPane=new JPanel();
JPanel jPane1=new JPanel();
JPanel jPane2=new JPanel();
jPane.setBackground(Color.RED );
jPane1.setBackground(Color.BLUE);
this.add(jContentPane);
GridBagLayout gbl=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
gbc.gridheight=3 ;
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbc.weightx=1.0;
gbc.weighty=1.0;
gbc.fill = GridBagConstraints.BOTH;
jContentPane.setLayout(gbl);
gbl.setConstraints(jPane1,gbc);
gbl.setConstraints(jPane,gbc);
gbl.setConstraints(jPane2, gbc);
jContentPane.add(jPane);
jContentPane.add(jPane1);
jContentPane.add(jPane2);
}
public static void main(String[] args) {
new test().setVisible(true);
}
}
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
public class test extends JFrame {
/**
* @param args
*/
public test(){
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
this.setSize(400,300 );
JPanel jContentPane=new JPanel();
jContentPane.setBackground(Color.BLACK);
JPanel jPane=new JPanel();
JPanel jPane1=new JPanel();
JPanel jPane2=new JPanel();
jPane.setBackground(Color.RED );
jPane1.setBackground(Color.BLUE);
this.add(jContentPane);
GridBagLayout gbl=new GridBagLayout();
GridBagConstraints gbc=new GridBagConstraints();
gbc.gridheight=3 ;
gbc.gridwidth=GridBagConstraints.REMAINDER;
gbc.weightx=1.0;
gbc.weighty=1.0;
gbc.fill = GridBagConstraints.BOTH;
jContentPane.setLayout(gbl);
gbl.setConstraints(jPane1,gbc);
gbl.setConstraints(jPane,gbc);
gbl.setConstraints(jPane2, gbc);
jContentPane.add(jPane);
jContentPane.add(jPane1);
jContentPane.add(jPane2);
}
public static void main(String[] args) {
new test().setVisible(true);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询