Click here to Skip to main content
15,885,855 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried hiding a window on closing by
Java
setDefaultCloseOperation(HIDE_ON_CLOSE);
.
But when I respawn the window by using
Java
setVisible(true)
the window appears with size 0, and none of the components are visible. Why does this happen and what could be the solution?


This is the code for MyClient class and ListenServerOpenWindow class in which i have changed the visibility of the ChatWindow which is another class

Java
public class MyClient extends WindowAdapter implements ActionListener
{
     **********
      MyClient(String name)throws IOException
      {
                windowsNames = new String[10];
                c= new ChatWindow[10];
                count =0; found =false;
              ********************
                 ListenServerOpenWindow m=new ListenServerOpenWindow(name,din,dout);
		Thread t=new Thread(m);
		t.start(); t.setName("Listening to Server for Request to Open Chat Window");
      }
      public void actionPerformed(ActionEvent e){
		// sending the messages
            try
            {
		if(e.getSource()==button){	
			System.out.println(list1+"test");
			str=(String)list1.getSelectedValue();
			dout3.writeUTF(str);
                        //Thread.currentThread().sleep(500);
                        found =false;
                        for(i=0;i<windowsnames.length;i++)>
                        {
                          if(windowsNames[i]!=null)
                            if(windowsNames[i].equalsIgnoreCase(str)&&windowsNames[i]!=null)
                          {
                              found=true; break;
                          }
                        }
                        if(found)
                        {
                            c[i].setVisible(true);
                        }
                        else
                        {
                            windowsNames[count]=str;
                            c[count++]=  new ChatWindow(name,str,din,dout);
                        }
                  }
            }catch(Exception ex){ex.printStackTrace();}
}



And the ListenServerOpenWindow class
Java
class ListenServerOpenWindow implements Runnable
{
    Socket s,s3;String chatwith,name; ChatWindow[] c;String[] windowsNames;
    DataInputStream din;DataOutputStream dout; int count; boolean found; int i;
    
    ListenServerOpenWindow(String name,DataInputStream din,DataOutputStream dout)
    {
       this.din = din;
       this.dout= dout;
        this.name=name;
        this.s=MyClient.s;
        this.s3 = MyClient.s3;
        c=new ChatWindow[10];
        windowsNames = new String[10];
        count =0;found =false;
        
    }
    public void run()
    {
        try
        {
            
            while(true)
            {
                
                
                DataInputStream d = new DataInputStream(s3.getInputStream());
               
                String cmd = d.readUTF();
                if(cmd.length()>9)
                {
                    
                    chatwith = cmd.substring(10);
                    
                    if(cmd.substring(0,10).equalsIgnoreCase("openwindow"))
                    {
                        //windowsNames[count]=chatwith;
                        found =false;
                        for(i=0;i<windowsnames.length;i++)>
                        {
                            if(windowsNames[i]!=null)
                          if(windowsNames[i].equalsIgnoreCase(chatwith))
                          {
                              found=true; break;
                          }
                        }
                        if(found)
                        {
                            c[i].setVisible(true);
                        }
                        else
                        {
                            windowsNames[count]=chatwith;
                            c[count++]=  new ChatWindow(name,chatwith,din,dout);
                        }
                    }
                }
            }
        }
        catch(Exception e){e.printStackTrace();}
    }
}



I have used
Java
setDefaultCloseOperation(HIDE_ON_CLOSE)
in the constructor of the ChatWindow class which extends JFrame class


On respawning the chatwindow, none of the components are shown
Posted
Updated 21-Oct-11 8:46am
v3
Comments
CodingLover 21-Oct-11 1:26am    
Can you show your code here to see?
GPUToaster™ 21-Oct-11 5:43am    
Unusual behavior.

1 solution

Problem solved. Solution was to use
Java
c[i].frame.setVisible(true);
where frame is the JFrame object
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900