Skip to main content

window not showing

No replies
vlie84
Offline
Joined: 2003-12-02
Points: 0

Hey guys i really need urgent help.

I have a JDialog called dlg and what happen is i add a menu bar called menubar during runtime to this JDialog.
to add menubar during runtime i use

class MyEventQueue extends EventQueue<br />
    {<br />
	protected void dispatchEvent(AWTEvent evt)<br />
	{<br />
	    super.dispatchEvent(evt);<br />
	    int id;<br />
	    id = evt.getID();</p>
<p>	    if ((id == WindowEvent.WINDOW_OPENED)||(id == WindowEvent.WINDOW_CLOSED))<br />
		{<br />
		    WindowEvent e;<br />
		    e = (WindowEvent) evt;<br />
		    Window comp;<br />
		    comp =  e.getWindow();</p>
<p>		    if (comp instanceof JDialog)<br />
                       {<br />
                          JDialog dlg;<br />
                          dlg = (JDialog) comp;<br />
                          dlg.setJMenuBar(menubar);<br />
                       dlg.setSize(dlg.getPreferredSize());<br />
                          dlg.validate();<br />
                          dlg.repaint();<br />
                        }<br />
		}<br />
	}<br />
    }<br />
//assume menubar already initialised somewhere.

what happen is it only display the dialog with grey window only.it doesnt show up the contents.
i used dlg.pack() before but it still not working.

i also try to do the addition inside invokeLater but it still not working.

i believe the addition of the menu bar is working because i can see the grey window is changing height but it just dont want to display all the components.

when i comment out dlg.validate() and dlg.repaint() it is also still not working.

do you know what could be the problem? any suggestion? any code sample will be helpful.

thank you so much