JavaSE(窗口编程中各部件介绍)

布局模式setLayout:

BorderLayout  //分为东西南北中五个位置可以放置窗口零件
FlowLayout  //按照窗口零件大小等属性,自动安排位置
null  
//jlblId.setBounds(0, top, lblWidth, lblHeight);绝对布局需要用setBunds设置位置 分别为左、上侧距离左、上侧零件的距离 以及该零件长度。
JRadioButton //单选按钮,当将几个JRadioButton加入到一个ButtonGroup内后,按钮只有一个能选中

例如:

private JRadioButton jrbtSexMale;
private JRadioButton jrbtSexFemale;

this.jrbtSexMale = new JRadioButton("男");
this.jrbtSexMale.setFont(normalFont);
this.jrbtSexMale.setBounds(lblWidth+MARGIN, top, 
		textLength*normalFontSize/2, normalFontSize+4);

this.jrbtSexFemale = new JRadioButton("女");
this.jrbtSexFemale.setFont(normalFont);
this.jrbtSexFemale.setBounds(lblWidth+MARGIN + this.jrbtSexMale.getWidth(), top, 
		textLength*normalFontSize/2, normalFontSize+4);
		
ButtonGroup btgpSex = new ButtonGroup();
btgpSex.add(this.jrbtSexMale);
btgpSex.add(this.jrbtSexFemale);
JComboBox	  //下拉框

例如:

private JComboBox<Integer> jcmbBirthYear;
this.jcmbBirthYear = new JComboBox<>();
this.jcmbBirthYear.setFont(normalFont);
this.jcmbBirthYear.setBounds(birthLeft, top, 4*normalFontSize, normalFontSize+4);
jpnlStuInfo.add(this.jcmbBirthYear);

JButton	  //单纯的按钮

例如:

this.jbtnHobbyAll = new JButton("全选");
this.jbtnHobbyAll.setFont(smallFont);

生成一片文本输入区:

private JTextArea jtatIntroduce;
private JScrollPane jscpIntroduce;

this.jtatIntroduce = new JTextArea();
this.jtatIntroduce.setFont(normalFont);
this.jscpIntroduce = new JScrollPane(this.jtatIntroduce);
TitledBorder ttbdIntroduce = new TitledBorder("简介");
ttbdIntroduce.setTitleFont(normalFont);
ttbdIntroduce.setTitlePosition(TitledBorder.ABOVE_TOP);
ttbdIntroduce.setTitleJustification(TitledBorder.CENTER);
this.jscpIntroduce.setBorder(ttbdIntroduce);

注意所有部件最后都要加到JPanel或者Jframe内

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

魔幻音

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值