小编Fos*_*los的帖子

Java GUI编译时没有错误,但有时没有显示任何内容

我正在使用扩展JFrame的自定义类,但有时它什么也没显示.我从来没有遇到过任何错误,所以我很好奇这是一个可以帮我打印东西的java命令.我环顾四周寻找其他问题,但没有发现任何相似之处.不是真的做了太疯狂的事情,但好奇为什么会这样.我想纠正这个问题,以避免将来出现问题.


空白
在此输入图像描述
GUI
在此输入图像描述

public MemberPanel(int i) throws IOException {
  Container contentPane = getContentPane();
  GridLayout layout = new GridLayout(2, 1);
  contentPane.setLayout(layout);
  setVisible(true);
  setLocation(0, 0);
  setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  setSize(640, 170);
  setResizable(false);

  greenStatus = new JButton("Non-Critical");
  yellowStatus = new JButton("Important");
  redStatus = new JButton("Mission Critical");

  greenStatus.setFont(fontTextOne);
  yellowStatus.setFont(fontTextOne);
  redStatus.setFont(fontTextOne);

  greenStatus.addActionListener(this);
  yellowStatus.addActionListener(this);
  redStatus.addActionListener(this);

  buttonPanel.add(greenStatus);
  buttonPanel.add(yellowStatus);
  buttonPanel.add(redStatus);

  statusLabel = new JLabel("In 75 letters or less... What are you working on?");
  statusLabel.setVerticalAlignment(JLabel.CENTER);
  statusLabel.setHorizontalAlignment(JLabel.CENTER);
  statusLabel.setFont(fontTextTwo);
  textFieldPanel.add(statusLabel);
  textFieldPanel.add(statusMessage);

  contentPane.add(buttonPanel);
  contentPane.add(textFieldPanel);

} 
Run Code Online (Sandbox Code Playgroud)

java user-interface swing

6
推荐指数
1
解决办法
2062
查看次数

标签 统计

java ×1

swing ×1

user-interface ×1