刚刚学习java不久,用Gridbaglayout,拉大JFrame没有问题,但是如果缩小到一定时候就会出现最上面的Menu bar被压得找不到了。其他的控件都是按比例变化的。不知道为什么?
怎么样才能控制一个控件的大小,让它是一个固定的值呢?谢谢!部分代码如下:
public JFrame  JF = new JFrame("Note");
public Container  JFC = JF.getContentPane();
public GridBagConstraints GBC = new GridBagConstraints();
public JMenuBar JMB = new JMenuBar();
public JToolBar JTB = new JToolBar(); public JTree JT = new JTree();
public JScrollPane JSPTree = new JScrollPane(JT);// public String lst[] = {"a","b","c","d","e","f","g","h","i"};
public JTable JTbl = new JTable(5,3);
public JScrollPane JSPList = new JScrollPane(JTbl);
public JLabel JLB  = new JLabel("aaa");
public JTextPane JTP = new JTextPane();
public JToolBar JTBSub = new JToolBar();
public JScrollPane JSPText = new JScrollPane(JTP); public JPanel JP = new JPanel();
private  void setGBC(int  fill, int  gridx, int  gridy, double  weightx,double weighty, int gridwidth, int gridheight){ GBC.fill  = fill; GBC.gridx = gridx; 
GBC.gridy = gridy; 
GBC.weightx = weightx; 
GBC.weighty = weighty; 
GBC.gridwidth  = gridwidth; 
GBC.gridheight = gridheight; } public void show(){ 
//Menu Bar 
setGBC(GridBagConstraints.BOTH,0,0,0,0,2,1); JFC.add(JMB, GBC); //Tool Bar 
this.setGBC(GridBagConstraints.BOTH,0,1,0,0,2,1); JFC.add(JTB,  GBC); //Tree of the left 
this.setGBC(GridBagConstraints.BOTH,0,2,1,1,1,2); 
JFC.add(JSPTree, GBC); //List 
this.setGBC(GridBagConstraints.BOTH,1,2,5,0.5,1,1); 
JFC.add(JSPList, GBC); //Sub Pan 
this.setGBC(GridBagConstraints.BOTH,1,3,5,0.5,1,1);
JFC.add(JP, GBC);
}困扰了好久了,如果大家给我点指点我将非常感激!谢谢!:)