Java中setLayout(null)导致组件不显示

唐加彬 2017-10-13 04:21:41
错误如题,直接贴代码。



package com.zwtj.tang.view;

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

public class TimerFrame extends JFrame{


private JLabel sys_h;
private JLabel sys_min;
private JLabel sys_s;


public TimerFrame( ){
super();
setTitle("时钟定时器");
setBounds(100,100,640,480);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container content = getContentPane();
setVisible(true);

//左上面板
JPanel leftPl = new JPanel();
leftPl.setLayout(null);
leftPl.setBounds(10,10,297,180);
leftPl.setBackground(Color.black);
content.add(leftPl);

//右上面板
JPanel rightPl = new JPanel();
rightPl.setLayout(null);
rightPl.setBounds(317,10,297,180);
rightPl.setBackground(Color.black);
content.add(rightPl);

//底部面板
JPanel bottomPanel = new JPanel();
bottomPanel.setLayout(null);
bottomPanel.setBounds(10,200,605,230);
bottomPanel.setBackground(Color.GRAY);
bottomPanel.setPreferredSize(new Dimension(605,230));
bottomPanel.setSize(605,230);
content.add(bottomPanel);

//左侧容器名称标签
JLabel sys_time = new JLabel();
sys_time.setText("当前系统时间:");
sys_time.setBounds(5,5,200,30);
sys_time.setFont(new Font("宋体",Font.BOLD,12));
sys_time.setForeground(Color.white);
leftPl.add(sys_time);

//系统_时分秒
sys_h = new JLabel();
sys_h.setText("00");
sys_h.setBounds(50,60,370,50);
sys_h.setFont(new Font("Digiface",Font.BOLD,42));
sys_h.setForeground(Color.red);
leftPl.add(sys_h);

//系统_冒号
JLabel colon_1 = new JLabel();
colon_1.setText(":");
colon_1.setBounds(100,55,30,50);
colon_1.setFont(new Font("Digiface",Font.BOLD,42));
colon_1.setForeground(Color.red);
leftPl.add(colon_1);

//系统_分
sys_min = new JLabel();
sys_min.setText("00");
sys_min.setBounds(120,60,70,50);
sys_min.setFont(new Font("Digiface",Font.BOLD,42));
sys_min.setForeground(Color.red);
leftPl.add(sys_min);

//系统_冒号
JLabel colon_2 = new JLabel();
colon_2.setText(":");
colon_2.setBounds(170,55,30,50);
colon_2.setFont(new Font("Digiface",Font.BOLD,42));
colon_2.setForeground(Color.red);
leftPl.add(colon_2);

//系统_秒
sys_s = new JLabel();
sys_s.setText("00");
sys_s.setBounds(190,60,70,50);
sys_s.setFont(new Font("Digiface",Font.BOLD,42));
sys_s.setForeground(Color.red);
leftPl.add(sys_s);

//右侧容器名称标签
JLabel timer_time = new JLabel();
timer_time.setText("倒计时时间:");
timer_time.setBounds(5,5,200,30);
timer_time.setFont(new Font("宋体",Font.BOLD,12));
timer_time.setForeground(Color.white);
rightPl.add(timer_time);

//倒计时_时
JLabel timer_h = new JLabel();
timer_h.setText("00");
timer_h.setBounds(60,60,70,50);
timer_h.setFont(new Font("Digiface",Font.BOLD,42));
timer_h.setForeground(Color.red);
rightPl.add(timer_h);

//倒计时_冒号
JLabel colon_3 = new JLabel();
colon_3.setText(":");
colon_3.setBounds(110,55,30,50);
colon_3.setFont(new Font("Digiface",Font.BOLD,42));
colon_3.setForeground(Color.red);
rightPl.add(colon_3);

//倒计时_分
JLabel timer_min = new JLabel();
timer_min.setText("00");
timer_min.setBounds(130,60,70,50);
timer_min.setFont(new Font("Digiface",Font.BOLD,42));
timer_min.setForeground(Color.red);
rightPl.add(timer_min);

//倒计时_冒号
JLabel colon_4 = new JLabel();
colon_4.setText(":");
colon_4.setBounds(180,55,30,50);
colon_4.setFont(new Font("Digiface",Font.BOLD,42));
colon_4.setForeground(Color.red);
rightPl.add(colon_4);

//倒计时_秒
JLabel timer_s = new JLabel();
timer_s.setText("00");
timer_s.setBounds(200,60,70,50);
timer_s.setFont(new Font("Digiface",Font.BOLD,42));
timer_s.setForeground(Color.red);
rightPl.add(timer_s);

//倒计时输入框_时
JTextField text_h = new JTextField();
text_h.setBounds(50,50,50,30);
bottomPanel.add(text_h);

//倒计时_时
JLabel colon_5 = new JLabel();
colon_5.setText("时");
colon_5.setBounds(110,40,30,50);
colon_5.setFont(new Font("黑体",Font.BOLD,24));
colon_5.setPreferredSize(new Dimension(30,50));
colon_5.setSize(30,50);
bottomPanel.add(colon_5);
}



public JLabel getSys_h() {
return sys_h;
}

public void setSys_h(JLabel sys_h) {
this.sys_h = sys_h;
}

public JLabel getSys_min() {
return sys_min;
}

public void setSys_min(JLabel sys_min) {
this.sys_min = sys_min;
}

public JLabel getSys_s() {
return sys_s;
}

public void setSys_s(JLabel sys_s) {
this.sys_s = sys_s;
}

}









在线等。麻烦各位大神了。
...全文
546 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
「已注销」 2017-10-15
  • 打赏
  • 举报
回复
给它传参数!

62,616

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧