AWT components in swing not working

Hi,

We are developing a swing based GUI application.

Here we add a third party AWT based component into the JPanel. But if we add that AWT component, it does not show our JMenuItems properly.

Can somebody tell me what is the problem with the code below? Why it is not displaying my JMenuItems ?

import java.awt.*;

import javax.swing.*;

public class ButtonTest extends JFrame

{

JMenuBar mbar;

JMenu file;

JMenuItem i1, i2, i3;

Container con;

public ButtonTest()

{

con = this.getContentPane();

con.setLayout(new BorderLayout());

mbar = new JMenuBar();

file = new JMenu("FILE");

i1 = new JMenuItem("Item1");

i2 = new JMenuItem("Item2");

i3 = new JMenuItem("Item3");

this.setJMenuBar(mbar);

file.add(i1);file.add(i2);file.add(i3);

mbar.add(file);

con.add(new Button("OK"));

}

public static void main(String args[])

{

JFrame mf = new ButtonTest();

mf.setSize(400 ,400);

mf.setVisible(true);

}

}

regards,

Anand

[1124 byte] By [kulk_ananda] at [2007-10-2 17:23:10]
# 1
As you've discovered, you cannot mix AWT and Swing components.I don't think there's any good workaround .. you'll need to pickone or the other.
es5f2000a at 2007-7-13 18:39:22 > top of Java-index,Desktop,Core GUI APIs...
# 2

Replace them with this.

import java.awt.*;

import javax.swing.*;

public class ButtonTest extends JFrame

{

JMenuBar mbar;

JMenu file;

JMenuItem i1, i2, i3;

Container con;

public ButtonTest()

{

con = this.getContentPane();

setSize(600,600);

mbar = new JMenuBar();

setLayout(new FlowLayout());

file = new JMenu("FILE");

i1 = new JMenuItem("Item1");

i2 = new JMenuItem("Item2");

i3 = new JMenuItem("Item3");

file.add(i1);file.add(i2);file.add(i3);

mbar.add(file);

con.add(new JButton("OK"));

setJMenuBar(mbar);

setVisible(true);

}

public static void main(String args[])

{

ButtonTest mf = new ButtonTest();

}

}

samue-1a at 2007-7-13 18:39:22 > top of Java-index,Desktop,Core GUI APIs...