Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Java Swing
I tried hiding a window on closing by
setDefaultCloseOperation(HIDE_ON_CLOSE);
.
But when I respawn the window by using
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
 
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
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
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 20-Oct-11 19:33pm
Edited 21-Oct-11 9:46am
v3
Comments
CodingLover at 21-Oct-11 1:26am
   
Can you show your code here to see?
GPUToaster™ at 21-Oct-11 5:43am
   
Unusual behavior.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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

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

  Print Answers RSS
0 OriginalGriff 515
1 Maciej Los 290
2 Richard MacCutchan 265
3 BillWoodruff 235
4 Suraj Sahoo | Coding Passion 175
0 OriginalGriff 8,804
1 Sergey Alexandrovich Kryukov 7,457
2 DamithSL 5,689
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411028.1 | Last Updated 21 Oct 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100