主要是Swing组件
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 import java.awt.FlowLayout; 2 import javax.swing.JFrame; 3 import javax.swing.JLabel; 4 import javax.swing.JTextField; 5 6 @SuppressWarnings("serial") 7 public class ShowFlowLayout extends JFrame{ 8 public ShowFlowLayout() { 9 setLayout(new FlowLayout(FlowLayout.LEFT,10,20)); 10 11 add(new JLabel("FirstName")); 12 add(new JTextField(8)); 13 add(new JLabel("MI")); 14 add(new JTextField(1)); 15 add(new JLabel("LastName")); 16 add(new JTextField(8)); 17 18 } 19 20 public static void main(String[] args) { 21 ShowFlowLayout frameFlowLayout=new ShowFlowLayout(); 22 frameFlowLayout.setTitle("Show FlowLayout"); 23 frameFlowLayout.setSize(500,100); 24 frameFlowLayout.setLocationRelativeTo(null); 25 frameFlowLayout.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 26 frameFlowLayout.setVisible(true); 27 } 28 }
最终达到下面的效果
JTab的应用
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 import java.awt.Dimension; 2 import java.awt.FlowLayout; 3 4 import javax.swing.JFrame; 5 import javax.swing.JLabel; 6 import javax.swing.JPanel; 7 import javax.swing.JTabbedPane; 8 9 public class JTab{ 10 public JTab(){ 11 12 JFrame frame=new JFrame("资金状况"); 13 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 14 frame.setVisible(true); 15 16 JTabbedPane tp =new JTabbedPane(); 17 frame.setContentPane(tp); 18 19 JPanel panel1=new JPanel(); 20 JPanel panel2=new JPanel(); 21 JPanel panel3=new JPanel(); 22 JPanel panel4=new JPanel(); 23 JPanel panel5=new JPanel(); 24 25 tp.addTab("panel1", panel1); 26 tp.setEnabledAt(0,true); 27 tp.setTitleAt(0, "个人收入状况"); 28 29 tp.addTab("panel2", panel2); 30 tp.setEnabledAt(1,true); 31 tp.setTitleAt(1, "工资"); 32 33 tp.addTab("panel3", panel3); 34 tp.setEnabledAt(2,true); 35 tp.setTitleAt(2, "奖金"); 36 37 tp.addTab("panel4", panel4); 38 tp.setEnabledAt(3,true); 39 tp.setTitleAt(3, "津贴"); 40 41 tp.addTab("panel5", panel5); 42 tp.setEnabledAt(4,true); 43 tp.setTitleAt(4, "社保"); 44 45 //设置选项卡在容器中的大小和位置 46 tp.setPreferredSize(new Dimension(500,200)); 47 tp.setTabPlacement(JTabbedPane.TOP); 48 //设置选项卡在容器内现实形式 49 tp.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); 50 51 frame.pack(); 52 JLabel l1=new JLabel("工资状况"); 53 panel2.setLayout(new FlowLayout()); 54 panel2.add(l1); 55 frame.pack(); 56 } 57 58 public static void main(String[] args) { 59 new JTab(); 60 } 61 }
这里