Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java标签消失_Java_Label_Frame - Fatal编程技术网

Java标签消失

Java标签消失,java,label,frame,Java,Label,Frame,我想做一个简单的议程,但不知何故,当我运行编译器时,它不会加载标签的文本,有时会加载。我该如何解决这个问题 例如: (无法显示图片) 下午13:00(这是经常出现的)课程A 下午13:30课程b 有时它会这样做: 下午13:00(总是出现)(然后什么都没有) 下午13:30 (请保持简单,因为我是初学者,来自荷兰) 代码: (我是初学者,所以不要看那些复制粘贴的东西) }移动frame.setVisible(true)到lastline将解决您的问题。添加组件后,您需要调用setvisible。

我想做一个简单的议程,但不知何故,当我运行编译器时,它不会加载标签的文本,有时会加载。我该如何解决这个问题

例如: (无法显示图片)

  • 下午13:00(这是经常出现的)课程A
  • 下午13:30课程b
  • 有时它会这样做:

  • 下午13:00(总是出现)(然后什么都没有)
  • 下午13:30
  • (请保持简单,因为我是初学者,来自荷兰)

    代码: (我是初学者,所以不要看那些复制粘贴的东西)


    }移动
    frame.setVisible(true)到lastline将解决您的问题。添加组件后,您需要调用setvisible。或者您可以调用repaint()、revalidate()


    你想让我们在没有UI代码或UI图像的情况下调试你的UI代码吗?我不认为这是代码的问题,它真的很奇怪。13:00pm我可以向你保证这是代码的问题。谢谢,成功了(我错了)
    import javax.swing.*;
    import java.awt.*;
    
    class P{
        public static void main(String [] args){
            JFrame frame = new JFrame(" Agenda 10/13/2014");
            frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
            frame.setSize(620,620);
            frame.setResizable(false);
            frame.setVisible(true);
    
        JLabel labeltime1 = new JLabel("1:00 - 1:30pm: ");
        JLabel labeltime2 = new JLabel("1:30 - 2:00pm: ");
        JLabel labeltime3 = new JLabel("2:00 - 2:30pm: ");
        JLabel labeltime4 = new JLabel("2:30 - 3:00pm: ");
        JLabel labeltime5 = new JLabel("3:00 - 3:30pm: ");
    
        labeltime1.setForeground(Color.red);
        labeltime2.setForeground(Color.red);
        labeltime3.setForeground(Color.red);
        labeltime4.setForeground(Color.red);
        labeltime5.setForeground(Color.red);
    
        JLabel space1 = new JLabel("\n");
        JLabel space2 = new JLabel("\n");
        JLabel space3 = new JLabel("\n");
        JLabel space4 = new JLabel("\n");
        JLabel space5 = new JLabel("\n");
    
        JPanel timeP = new JPanel();
        timeP.setBackground(Color.black);
        timeP.setLayout(new BoxLayout(timeP, BoxLayout.Y_AXIS));
    
        timeP.add(space5);
        timeP.add(labeltime1);
        timeP.add(space1);
        timeP.add(labeltime2);
        timeP.add(space2);
        timeP.add(labeltime3);
        timeP.add(space3);
        timeP.add(labeltime4);
        timeP.add(space4);
        timeP.add(labeltime5);
    
        frame.getContentPane().add(BorderLayout.WEST, timeP);
    
        JPanel courses = new JPanel();
        courses.setLayout(new BoxLayout(courses, BoxLayout.Y_AXIS));
        courses.setBackground(Color.black);
        frame.getContentPane().add(BorderLayout.CENTER,courses);
    
        //Enter your course
        JLabel course1 = new JLabel(" Course A");
        JLabel course2 = new JLabel(" Course B");
        JLabel course3 = new JLabel(" Course C");
        JLabel course4 = new JLabel(" Course D");
        JLabel course5 = new JLabel(" Course E");
    
        course1.setForeground(Color.yellow);
        course2.setForeground(Color.yellow);
        course3.setForeground(Color.yellow);
        course4.setForeground(Color.yellow);
        course5.setForeground(Color.yellow);
    
        JLabel space6 = new JLabel("\n");
        JLabel space7 = new JLabel("\n");
        JLabel space8 = new JLabel("\n");
        JLabel space9 = new JLabel("\n");
        JLabel space10 = new JLabel("\n");
    
        courses.add(space6);
        courses.add(course1);
        courses.add(space7);
        courses.add(course2);
        courses.add(space8);
        courses.add(course3);
        courses.add(space9);
        courses.add(course4);
        courses.add(space10);
        courses.add(course5);
    
    
    }
    
    import javax.swing.*;
    import java.awt.*;
    
    class P{
        public static void main(String [] args){
            JFrame frame = new JFrame(" Agenda 10/13/2014");
            frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
            frame.setSize(620,620);
            frame.setResizable(false);
            //frame.setVisible(true);//don't call this method here
    
        JLabel labeltime1 = new JLabel("1:00 - 1:30pm: ");
        JLabel labeltime2 = new JLabel("1:30 - 2:00pm: ");
        JLabel labeltime3 = new JLabel("2:00 - 2:30pm: ");
        JLabel labeltime4 = new JLabel("2:30 - 3:00pm: ");
        JLabel labeltime5 = new JLabel("3:00 - 3:30pm: ");
    
        labeltime1.setForeground(Color.red);
        labeltime2.setForeground(Color.red);
        labeltime3.setForeground(Color.red);
        labeltime4.setForeground(Color.red);
        labeltime5.setForeground(Color.red);
    
        JLabel space1 = new JLabel("\n");
        JLabel space2 = new JLabel("\n");
        JLabel space3 = new JLabel("\n");
        JLabel space4 = new JLabel("\n");
        JLabel space5 = new JLabel("\n");
    
        JPanel timeP = new JPanel();
        timeP.setBackground(Color.black);
        timeP.setLayout(new BoxLayout(timeP, BoxLayout.Y_AXIS));
    
        timeP.add(space5);
        timeP.add(labeltime1);
        timeP.add(space1);
        timeP.add(labeltime2);
        timeP.add(space2);
        timeP.add(labeltime3);
        timeP.add(space3);
        timeP.add(labeltime4);
        timeP.add(space4);
        timeP.add(labeltime5);
    
        frame.getContentPane().add(BorderLayout.WEST, timeP);
    
        JPanel courses = new JPanel();
        courses.setLayout(new BoxLayout(courses, BoxLayout.Y_AXIS));
        courses.setBackground(Color.black);
        frame.getContentPane().add(BorderLayout.CENTER,courses);
    
        //Enter your course
        JLabel course1 = new JLabel(" Course A");
        JLabel course2 = new JLabel(" Course B");
        JLabel course3 = new JLabel(" Course C");
        JLabel course4 = new JLabel(" Course D");
        JLabel course5 = new JLabel(" Course E");
    
        course1.setForeground(Color.yellow);
        course2.setForeground(Color.yellow);
        course3.setForeground(Color.yellow);
        course4.setForeground(Color.yellow);
        course5.setForeground(Color.yellow);
    
        JLabel space6 = new JLabel("\n");
        JLabel space7 = new JLabel("\n");
        JLabel space8 = new JLabel("\n");
        JLabel space9 = new JLabel("\n");
        JLabel space10 = new JLabel("\n");
    
        courses.add(space6);
        courses.add(course1);
        courses.add(space7);
        courses.add(course2);
        courses.add(space8);
        courses.add(course3);
        courses.add(space9);
        courses.add(course4);
        courses.add(space10);
        courses.add(course5);
        frame.setVisible(true);//call here
    
    }
    
    }