问题描述
publicFrameTest4(){//设置顶级容器ContainerContain=this.getContentPane();//给整个容器设置左右两个面板jpLeftjpRight;//JLabeljpLeft=newJLabel();//JLabeljpRight=newJLabel();//把jpRight分割成两个面板jpRightUpjpRightDownJLabeljpRightUp=newJLabel();//JLabeljpRightDown=newJLabel();//把jpLeft分割成两个面板jpLeftUpjpLeftDownJLabeljpLeftUp=newJLabel();JLabeljpLeftDown=newJLabel();//把右下边的面板再次进行分割jpRightDown1=newJPanel();jpRightDown2=newJPanel();//(1)在左上边容器中添加按钮//注意:要使用组件的.setBounds(380,370,10,20);方法,其容器的布局必须是null,则setLayout(null);jpLeftUp.setLayout(null);//设置其行列jpLeftUp.setBackground(newColor(25,187,190));JButtonJB1=newJButton("人事部门");JB1.setBounds(40,30,120,35);JButtonJB2=newJButton("财务部门");JB2.setBounds(40,75,120,35);JButtonJB3=newJButton("管理部门");JB3.setBounds(40,120,120,35);JButtonJB4=newJButton("技术部门");JB4.setBounds(40,165,120,35);jpLeftUp.add(JB1);jpLeftUp.add(JB2);jpLeftUp.add(JB3);jpLeftUp.add(JB4);Contain.add(jpLeftUp);
解决方案
解决方案二:
JLabel是默认透明的组件想改变它的背景色不仅仅是一句setBackground就够的还需要加一句setOpaque(true);