GridBagLayout不能正常显示 问题在哪 没有异常输出

人生万事须自为,跬步江山即寥廓。 人生万事须自为,跬步江山即寥廓。 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
import java.awt.*;

import javax.swing.*;
import javax.swing.border.LineBorder;


public class CategoryPanel extends JPanel {

/**build the categorypanel for the series warehouse handling
*
* @param args
*/
public CategoryPanel(){
String [] s = {"20000","40000","60000","60000","00008","400000","900000","00002"};
JList brandlist = new JList(s);
brandlist.setPreferredSize(new Dimension(120,30));
JList serieslist = new JList(s);
JLabel namelabel = new JLabel("name");
JTextField nametf = new JTextField(20);
JLabel amountlabel = new JLabel("amount");
JTextField amounttf= new JTextField(20);
JLabel pricelabel = new JLabel("price");
JTextField pricetf = new JTextField(20);
JLabel discountlabel = new JLabel("discount");
JTextField discounttf = new JTextField(20);

JPanel inputpanel = new JPanel();
GridBagLayout gbl = new GridBagLayout();
inputpanel.setLayout(gbl);
JPanel enterpanel = new JPanel();
JButton ok = new JButton("ok");
ok.setPreferredSize(new Dimension(120,30));
//enterpanel.setLayout(new GridLayout(1,4));
enterpanel.add(ok);


inputpanel.add(new JScrollPane(brandlist),new GBC(0,0).setFill(GBC.VERTICAL).setWeight(0, 0).setAnchor(GBC.CENTER));
inputpanel.add(new JScrollPane(serieslist),new GBC(1,0).setFill(GBC.HORIZONTAL).setWeight(0, 0));
inputpanel.add(namelabel,new GBC(2,0).setFill(GBC.HORIZONTAL).setWeight(0, 0));
inputpanel.add(nametf,new GBC(3,0).setFill(GBC.HORIZONTAL).setWeight(0, 0));
inputpanel.add(amountlabel,new GBC(4,0).setInsets(20).setFill(GBC.BOTH).setWeight(0, 0));
inputpanel.add(amounttf,new GBC(5,0).setInsets(20).setFill(GBC.BOTH).setWeight(0, 0));
inputpanel.add(pricelabel,new GBC(6,0).setInsets(20).setFill(GBC.BOTH).setWeight(0, 0));
inputpanel.add(pricetf,new GBC(7,0).setInsets(20).setFill(GBC.BOTH).setWeight(0, 0));
inputpanel.add(discountlabel,new GBC(8,0).setInsets(20).setFill(GBC.BOTH).setWeight(0, 0));
inputpanel.add(discounttf,new GBC(9,0).setInsets(20).setFill(GBC.BOTH).setWeight(0, 0));

LineBorder lb = new LineBorder(Color.cyan,2);
inputpanel.setBorder(lb);

setLayout(new BorderLayout());
add(inputpanel, BorderLayout.CENTER);
add(enterpanel, BorderLayout.SOUTH);

}
public static void main(String[] args) {
// TODO Auto-generated method stub
JFrame f = new JFrame();
f.add(new CategoryPanel());
f.setSize(900,320);
f.setVisible(true);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}


import java.awt.*;
import javax.swing.*;


public class GBC extends GridBagConstraints{

/**Constructs a GBC with a given gridx and gridy position and all other
* gridbag constraint values set to the default.
* @param gridx the gridx position
* @param gridy the gridy position
*/
public GBC(int gridx,int gridy){
this.gridx = gridx;
this.gridy = gridy;

}

/**Constructs a GBC with given gridx,gridy,gridwidth,gridheight and all other gridbag
* constraint values set to the default.
*
* @param gridx the gridx position
* @param gridy the gridy position
* @param gridwidth the cell span in x-direction
* @param gridheight the cell span in y-direction
*/
public GBC(int gridx,int gridy,int gridwidth, int gridheight){
this.gridx = gridx;
this.gridy = gridy;
this.gridwidth = gridwidth;
this.gridheight = gridheight;

}

/**Sets the anchor
*
* @param anchor the anchor value
* @return this object for further modification
*/
public GBC setAnchor(int anchor){
this.anchor = anchor;
return this;
}

/**Sets the fill direction
* @param fill the fill direction
* @return this object for further modification
*
*/

public GBC setFill(int fill){
this.fill = fill;
return this;

}

/**Sets the cell weight
* @param weightx the cell weight in x-direction
* @param weighty the cell weight int y-direction
* @return this object for further modification
*/

public GBC setWeight(double weightx , double weighty){
this.weightx = weightx;
this.weighty = weighty;
return this;
}

/**Sets the insets of this cell.
* @param distance the spacing to use all directions
* @return this object for further modification
*/

public GBC setInsets(int distance){
this.insets= new Insets(distance,distance,distance,distance);
return this;

}

/**Sets the insets of this cell.
* @param top the spacing to use on top
* @param left the spacing to use to the left
* @param bottom the spacing to use on the bottom
* @param right the spacing to use to the right
* @return this object for further modification
*
*/
public GBC setInsets(int top, int left, int bottom, int right){
this.insets = new Insets(top,left, bottom,right);
return this;
}

/**Sets the internal padding
* @param ipadx the internal padding in x-direction
* @param ipady the internal padding in y-direction
* @return this object for further modification
*/

public GBC setIpad(int ipadx, int ipady){
this.ipadx = ipadx;
this.ipady = ipady;
return this;
}



}
...全文

相关推荐

评论 4
收藏 已收藏
分享
返回顶部
人生万事须自为,跬步江山即寥廓。
人生万事须自为,跬步江山即寥廓。 优质创作者: 编程框架、人工智能技术领域 优质创作者: 编程框架、人工智能技术领域
Java SE 62,621 成员 307,251 内容