Mcolo Mcolo - 10 months ago 43
Java Question

I am having some issues regarding jframe and jlabel?

I am making simple login screen. I added two JLabel's in JFrame in my program and it's running successfully but the problem is that when I run the program I got blank screen and empty jframe, however I have added two jlabel's in that frame but it's not showing me any thing and then if I minimize the window and after some time if I open that window again then I can see those components.

Here is my code:

package javaapplication41;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.*;

public class JavaApplication41 {

JFrame cpec=new JFrame();
JLabel l = new JLabel(new ImageIcon("C:\\Users\\MUHAMMAD SHAHAB\\Documents\\NetBeansProjects\\Real Estate\\src\\real\\estate\\file (2).jpg"));
JLabel kiq=new JLabel(new ImageIcon("C:\\Users\\MUHAMMAD SHAHAB\\Documents\\NetBeansProjects\\Real Estate\\src\\real\\estate\\bla.jpg"));
public static void main(String[] args) {
JavaApplication41 ne=new JavaApplication41();


I am getting this output when I run program:

blank window

and when I minimize this window and again open this, then I am getting the desired output here it is:

enter image description here

what am I doing wrong?

Answer Source

You have to put cpec.setVisible(true); after adding all the items in your jframe.I hope this will surely solve your problem