Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Swing/AWT conversion problem

Status
Not open for further replies.

rotovegasBoy

Programmer
Sep 16, 1999
88
NZ
I've got a gui written using the AWT libraries and i'm re-coding it using the swing libraries and i've run into a problem i've got a main application window with menus i'm adding a panel to it in a child class.&nbsp;&nbsp;In doing this the menus now drop down behind the panel. I've tried re ordering the way things are added but thats not working.&nbsp;&nbsp;Heres the code from my adding widgets part<br>p is currently a awt panel me is the main application and m* is any menu widget.<br><br><FONT FACE=monospace><br>me.getContentPane().add(me.p);<br>me.mb.add(m);<br>m.add(mm);<br>me.pack();<br>me.show();<br>me.setSize(900,700);<br>me.monitor2P();<br></font><br>
 
mmmmm in Swing it would look something like this..<br>if you are using a Window container as against a Frame container, you must use the JWindow.. and I believe is the same procedure... as JFrame<br>dont know if this was of help? :D<br><br>import javax.swing.*;<br>import java.awt.*;<br><br>public class myMenus extends JFrame<br>{ private JMenuBar mb;<br>&nbsp;&nbsp;private JMenu m;<br>&nbsp;&nbsp;private JMenuItem exitMi;<br>&nbsp;&nbsp;private JPanel normalPanel;<br>&nbsp;&nbsp;private JButton nothingB;<br>&nbsp;&nbsp;<br>&nbsp;public myMenus()<br>&nbsp;{ m = new JMenu(&quot;File&quot;);<br>&nbsp;&nbsp;&nbsp;mb = new JMenuBar()<br>&nbsp;&nbsp;&nbsp;exitMi = new JMenuItem(&quot;Exit&quot;);<br>&nbsp;&nbsp;&nbsp;nothingB = new JButton(&quot;Nothing&quot;);<br>&nbsp;&nbsp;&nbsp;normalPanel = new JPanel();<br>&nbsp;&nbsp;&nbsp;m.add(exitMi);<br>&nbsp;&nbsp;&nbsp;mb.add(m);<br>&nbsp;&nbsp;&nbsp;setJMenuBar(mb);<br>&nbsp;&nbsp;&nbsp;normalPanel.add(nothingB);<br>&nbsp;&nbsp;&nbsp;getContentPane().add(normalPanel, BorderLayout.CENTER);<br>&nbsp;&nbsp;}<br>&nbsp;public static void main (String [] ar)<br>{ myMenus f = new myMenus();<br>&nbsp;&nbsp;&nbsp;f.setVisible(true);<br>&nbsp;&nbsp;}<br>&nbsp;}<br>&nbsp;&nbsp;&nbsp;<br><br>&nbsp;&nbsp;
 
In your code if you add an awt label before the button the menu disappears behind it. I guess the solution to my problem is to make my awt panel into a swing panel which is going to take some time.&nbsp;&nbsp;If anyone has an idea about how to fix it without complete conversion I'd like to hear it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top