布局模式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内